Advertisement

02.28.2006 at 11:05AM PST, ID: 21755099
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Searching fileds using LIKE in tables with more than 500000 records.

Asked by syrma in MySQL Server

Tags: , ,

I'm performing some tests on a big database.
This is the table I'm currently testing.

CREATE TABLE `subscribers` (
  `subscriber_id` int(11) NOT NULL auto_increment,
  `client_id` int(11) NOT NULL,
  `subscriber_fname` varchar(64) default NULL,
  `subscriber_lname` varchar(64) default NULL,
  `subscriber_email` varchar(128) default NULL,
  `subscriber_newsletters` text,
  `subscriber_date` datetime default NULL,
  PRIMARY KEY  (`subscriber_id`),
  KEY `subscriber_email` (`subscriber_email`),
  KEY `subscriber_fname` (`subscriber_fname`),
  KEY `subscriber_lname` (`subscriber_lname`)
)

The 3 fields I need to sort by are indexed.
I have imported 540000 randomly generated records. All emails look like this: "somerandomstring@mydomain.com"
I'm working on a search form and I'm searching the email field using LIKE. The problem is that I'm getting extremely different time depending on what I'm searching for.

Here are some examples:

SELECT *
FROM `subscribers`
WHERE `subscriber_email` LIKE '%mydomain.com%'
LIMIT 0 , 100

Showing rows 0 - 99 (100 total, Query took 0.0014 sec)

--------------------

SELECT *
FROM subscribers
WHERE `subscriber_email` LIKE '%fa11d41aa4%'
LIMIT 0 , 100

Showing rows 0 - 24 (25 total, Query took 2.4643 sec)

--------------------

SELECT subscriber_fname, subscriber_lname, subscriber_email, client_id, subscriber_id
FROM subscribers
WHERE subscriber_email LIKE "%mydomain.com%"
ORDER BY subscriber_fname ASC
LIMIT 0 , 100

Showing rows 0 - 99 (100 total, Query took 0.0018 sec)

--------------------

SELECT subscriber_fname, subscriber_lname, subscriber_email, client_id, subscriber_id
FROM subscribers
WHERE subscriber_email LIKE "%fa11d41aa4%"
ORDER BY subscriber_fname ASC
LIMIT 0 , 100

There are 25 rows corresponding to this query (fa11d41aa4@mydomain.com) - the query does not execute in 30 sec.
--------------------

SELECT *
FROM subscribers
WHERE `subscriber_email` LIKE '%nonexistingstring%'
LIMIT 0 , 100

MySQL returned an empty result set (i.e. zero rows). (Query took 2.2848 sec)
--------------------

I wonder why the execution time is so different depending on what I'm searching.

Thank youStart Free Trial
[+][-]02.28.2006 at 11:14AM PST, ID: 16068325

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MySQL Server
Tags: mysql, like, searching
Sign Up Now!
Solution Provided By: todd_farmer
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.28.2006 at 12:03PM PST, ID: 16068824

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2006 at 12:04PM PST, ID: 16068825

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2006 at 12:04PM PST, ID: 16068836

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2006 at 12:05PM PST, ID: 16068848

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32