Hello everyone,
I am having a strange problem I cannot figure out...
I have a table callled tracking_clickstreams:
id - unsigned bigint primary key unique
fkey_session - unsigned mediumint
fkey_url - unsigned mediumint
stamper - timestamp
The table has an index on the id field, and a compound index on stamper + fkey_session
I am trying to get all ids that fall within a particular date range and have a particular fkey_session value. My querey is:
SELECT count(c.id) FROM tracking_clickstream AS c WHERE c.stamper>=20031001000000 && c.stamper<=20031112235959 && c.fkey_session=37;
This query results in 5009 rows selected from a possible 4.2 million. The problem is that no index is used! When I perform an explain I see the index under "possible keys", however no key is used and the entire table is instead scanned. This results in this query taking a while.
I have tried to force the index via "USE INDEX" to no avail. The query returns only a small portion of the dataset so I don't see why it is not using the stamper+fkey_session index.
When I modify the query to be a smaller date range, however, the proper index is used.
The problem though, is the larger date range only kicks back 5009 out of 4.2 million rows, which is .10% of the data? Why would it not use an index?
I am having a strange problem I cannot figure out...
I have a table callled tracking_clickstreams:
id - unsigned bigint primary key unique
fkey_session - unsigned mediumint
fkey_url - unsigned mediumint
stamper - timestamp
The table has an index on the id field, and a compound index on stamper + fkey_session
I am trying to get all ids that fall within a particular date range and have a particular fkey_session value. My querey is:
SELECT count(c.id) FROM tracking_clickstream AS c WHERE c.stamper>=20031001000000 && c.stamper<=20031112235959 && c.fkey_session=37;
This query results in 5009 rows selected from a possible 4.2 million. The problem is that no index is used! When I perform an explain I see the index under "possible keys", however no key is used and the entire table is instead scanned. This results in this query taking a while.
I have tried to force the index via "USE INDEX" to no avail. The query returns only a small portion of the dataset so I don't see why it is not using the stamper+fkey_session index.
When I modify the query to be a smaller date range, however, the proper index is used.
The problem though, is the larger date range only kicks back 5009 out of 4.2 million rows, which is .10% of the data? Why would it not use an index?