Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a SQL ANSI way of starting a search at the end of table?

In a certain app I must constantly query data that are likely to be amongst the last inserted rows. Since this table is going to grow a lot, I wonder if theres a standard way of optimizing the queries by making them start the lookup at the table's end. I think I would get the same optmization if the database stored data for the table in a stack-like structure, so the last inserted rows would be searched first.

like image 517
Thiago Padilha Avatar asked Dec 02 '22 05:12

Thiago Padilha


1 Answers

The SQL spec doesn't mention anything about maintaining the insertion order. In practice, most of decent DB's also doesn't maintain it. Then it stops here. Sorting the table first ain't going to make it faster. Just index the column(s) of interest (at least the ones which you use in the WHERE).

like image 92
BalusC Avatar answered Dec 03 '22 23:12

BalusC