![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm running a site with very specific queries. That is to say, there are not lots of different queries on any particular table, so I'm not out for general optimization, but want indexing specifically for this query: *SELECT * * * * * * FROM * * * slot_purchases * * WHERE * * * position_price = $amount * * * AND status IS NULL * * ORDER BY * * * ts DESC given this DDL (or DML, I never know the diff between those terms (grin)) CREATE TABLE IF NOT EXISTS `slot_purchases` ( * `user_id` int(11) NOT NULL, * `position_price` int(11) NOT NULL, * `status` int(11) default NULL, * `transaction_id` varchar(45) NOT NULL, * `transaction_details` text NOT NULL, * `ts` timestamp NOT NULL default CURRENT_TIMESTAMP, * PRIMARY KEY *(`user_id`,`transaction_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Because this query will be executed from Perl/DBI the $amount will be turned into a placeholder by SQL::Interp before sending to the - prepare() call of DBI. |
#3
| |||
| |||
|
|
I'm running a site with very specific queries. That is to say, there are not lots of different queries on any particular table, so I'm not out for general optimization, but want indexing specifically for this query: SELECT * FROM slot_purchases WHERE position_price = $amount AND status IS NULL ORDER BY ts DESC given this DDL (or DML, I never know the diff between those terms (grin)) |

#4
| |||
| |||
|
|
On 2011-10-06, Terrence Brannon<thequietcenter (AT) gmail (DOT) com> wrote: I'm running a site with very specific queries. That is to say, there are not lots of different queries on any particular table, so I'm not out for general optimization, but want indexing specifically for this query: SELECT * FROM slot_purchases WHERE position_price = $amount AND status IS NULL ORDER BY ts DESC given this DDL (or DML, I never know the diff between those terms (grin)) DDL is CREATE, DROP etc, DML is INSERT, UPDATE, DELETE (etc) IMO the generic term is SQL ![]() I'd go for a partial index (where status IS NULL) on position_price and ts something like this: CREATE INDEX some_index_name ON slot_purchases(position_price,ts) WHERE status IS NULL; |
#5
| |||
| |||
|
|
CREATE INDEX some_index_name ON slot_purchases(position_price,ts) WHERE status IS NULL; Error: near "where": syntax error sqlite Which what database did you do that? |
#6
| |||
| |||
|
|
I'm running a site with very specific queries. That is to say, there are not lots of different queries on any particular table, so I'm not out for general optimization, but want indexing specifically for this query: SELECT * FROM slot_purchases WHERE position_price = $amount AND status IS NULL ORDER BY ts DESC given this DDL (or DML, I never know the diff between those terms (grin)) |
![]() |
| Thread Tools | |
| Display Modes | |
| |