DEV Community

Discussion on: 1 SQL Query You Should Stop Using

Collapse
 
bhupesh profile image
Bhupesh Varshney 👾

I am not good in this aspect but wouldn't indexing help in this ?

Collapse
 
abdisalan_js profile image
Abdisalan

That's okay! I'm learning as well :)

In my testing, I used an index to help with the OFFSET and the results are improved but still no where near as good as the cursor method.

The results you see in the article are me using an index.

Collapse
 
lukecarrier profile image
Luke Carrier

With the disclaimer that I'm no expert, there are two different types of index:

  • Clustered indices affect the layout of the data on the disk. This is why primary key lookups are relatively fast: the database engine is able to calculate the offset within the data file where it expects to find a row from the index.
  • Non-clustered indices are an intermediary between a set of values in the row and the row's primary key. These incur an additional lookup.
Collapse
 
abdisalan_js profile image
Abdisalan

Interesting, I'll have to learn more about this Luke. Good point!