orslumen/record-cache — Issue #14: Record-cache saying SQL query is "Not Cacheable"
Author: dhruvg
Created: 2012-01-27 23:32:39+00:00
State: open

Wondering why the following query is not cacheable:

I am seeing the following in my logs:
Not cacheable (SELECT status = 0 AND post_id = "07c3c662-493a-11e1-974d-069679418f38"): SQL = SELECT `topic_post_edges`.* FROM `topic_post_edges` WHERE `topic_post_edges`.`status` = 0 AND `topic_post_edges`.`post_id` = '07c3c662-493a-11e1-974d-069679418f38'

The SQL is:

SELECT `topic_post_edges`.* FROM `topic_post_edges` WHERE `topic_post_edges`.`status` = 0 AND `topic_post_edges`.`post_id` = '07c3c662-493a-11e1-974d-069679418f38'

The table schema is:

+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| topic_id | varchar(255) | NO | MUL | NULL | |
| post_id | varchar(255) | NO | MUL | NULL | |
| status | tinyint(4) | NO | | 0 | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| user_id | varchar(255) | NO | MUL | NULL | |
+------------+--------------+------+-----+---------+----------------+

I have made the above table a little easier to read, but basically, the post_id column is indexed. Thus, it meets the requirements in the documentation, right?

it contains at least one where(:id => ...) or where( => ...) clause, and
(indexed attribute is post_id)

it contains zero or more where( => ) clauses on attributes in the same model, and
(attribute is status, single value is 0, on the same model)

no limit, no order clause
no join, group by..

Could someone shed light on this?