1

I need some help cutting the execution time on this query. 7 seconds seems too long for a table with 1500 rows.

  SELECT parent
    FROM video
   WHERE parent NOT IN (SELECT parent
                          FROM video
                         WHERE filename REGEXP '(s[0-9]{2}\e[0-9]{2})|([[:<:]][0-9]{3}[[:>:]])')
GROUP BY parent
2
  • 1
    Does the column parent have an index? Using regex in a query is probably also a reason why its slow. Commented Jun 28, 2011 at 2:02
  • @datasage: Correct, should've been an answer Commented Jun 28, 2011 at 2:14

2 Answers 2

5

First, you can use NOT REGEXP instead of a subquery.

SELECT parent
FROM video
WHERE filename NOT REGEXP '(s[0-9]{2}\e[0-9]{2})|([[:<:]][0-9]{3}[[:>:]])'
GROUP BY parent

When using REGEXP or NOT REGEXP, the indexes don't matter. To make it more efficient, if that's still not enough, you'll have to look at using other string functions or the LIKE operator.

Sign up to request clarification or add additional context in comments.

3 Comments

Would this regex be faster with java? I did have everything being parsed through java with regex leaving clean data for my database, but with this new method using regex with queries, I've reduced the amount of code i need by about 50%..
@aLk: No, Java will never scale as well as the database can to large data sets.
@aLk - You could always pull all of the data in Java and use it's functions to sort the data. My advice is try using a single query (using NOT REGEXP) and do the same with all of the data using Java and time the execution. If you can run your script through a command line, the time(2) command might help.
2

Two quick things:

  • Ensure the parent column is indexed.
  • Drop the regular expression. If you can, use LIKE or some other string function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.