I have the following (My)SQL query:
SELECT * FROM table WHERE nidx = x ORDER BY id DESC LIMIT 1
With the following assumptions:
idis an indexed fieldnidxis a non-indexed field (let's say it has a numerical type)xis a constant- record with
nidx = xis relatively close in the ordered sequence of records (let's say it is guaranted to be somewhere among the first 1000 records in the order)
I have two questions:
- Can I assume that this is an efficient query or should I add an index to
nidxcolumn? - Does the answer to the first question depends on the specific RDBMS (so it may by different for MySQL, PostgreSQL, MSSQL, SQLite, etc.)? If yes, how it is for MySQL?