mysql - Optimizing a SQL query by only looking in the last X rows (Not simply LIMIT) -


i perform sql query across large table. however, need through last 100,000 rows. currently:

select * bigtable columna='foobar' order id desc limit 10  

i same make in last x ids.

edit: selecting 100k rows first , selecting not solution. selects full previous 100k rows, if more 10 of needed rows have been found. makes slower.

in database cannot query checks "last x rows". relational database not guarantee rows physically stored in specific order. , therefore sql not allow express that. if can translate actual constraint based on data contained in rows possible achieve.

taking example, worst operation database has sort of full result set before returning data. regardless of limit clause, because after run through rows , sorted them know rows have highest ids.

however, if there index columna , id, order, database engine should use index, sorted, go through rows faster, resulting in faster response time.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -