1

I just ran into a curious issue with MySQL. I had a very slow query, even if properly indexed, which was like this:

SELECT * FROM `tbl1` WHERE `parm1` = 'taleggio' AND `parm2` = 10

As said both parm1 and parm2 had indexes. The query was taking from 0.2s up to 120s, depending on the searched values.

Then I quoted the search terms like this:

SELECT * FROM `tbl1` WHERE `parm1` = 'taleggio' AND `parm2` = '10'

and now the execution takes 0.02s! Why that?

3
  • no, taleggio is not a column or I'd have an error
    – Maxxer
    Commented Jul 7, 2015 at 6:41
  • you're probably right, I miscopied the statement... updating it
    – Maxxer
    Commented Jul 7, 2015 at 7:38
  • if you are interested in: here is a good online book abou indexes use-the-index-luke.com/sql/table-of-contents
    – miracle173
    Commented Jul 7, 2015 at 7:52

1 Answer 1

0

First query should give you an error as you're filtering items with string, the datatype would be CHAR or VARCHAR.

If you you integer, in same columns, the query will rub without quotes but it will be slow because of string datatype.

Second Query is proper written,

However for more performence, you can also create combine index on (parm1, parm2) with

CREATE INDEX tbl11 ON tbl1 (parm1, parm2))
1
  • the first query has been running fine for months... no error thrown
    – Maxxer
    Commented Jul 7, 2015 at 6:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.