The query is:
SELECT T.ID, T.A, T.T
FROM table1 AS T
WHERE (userID='333335') AND (category LIKE '1%') AND (T.T='You Ain\'t Much
Fun' AND T.A='KEITH, TOBY') GROUP BY T.A, T.T
I have a BTREE index over 2 columns - userID, and another column which doesn't feature in the above query. The index is set up with userID being the first column.
The table is innoDB, and the total table size is around 70 million, but the rows that userID='333335' equals total only about 500,000.
If userID has an index on it, and that's the first column queried, shouldn't the rest of the query be able to breeze through 500,000 rows pretty quickly?
What is it that I'm overlooking please?
Thank you for your time and help.
SHOW CREATE TABLE
; ifcategory
is numeric, there is a problem. What is thePRIMARY KEY
?GROUP BY a,t
when you also test for equality on those columns?T.ID
? There would be two of them, and theGROUP BY
would deliver one of them at random. Perhaps you wantGROUP_CONCAT(T.ID)
?category LIKE '1%'
requires converting every row'scategory
fromINT
toVARCHAR
, then check for stating with1
. Note that that implies 1, 10,11,...,19, 100,101,...,199, etc. Did you really need to be checking for that??