When do not use ORDER BY, as shown below, it takes only the 0.2 sec response time which is what I want. The problem is - it is fetching the older data, I need to get the last 15 records inserted into the table student.

Is there any way to sort the data without using ORDER BY? If not, how can I speed up the query?

It seems strange to me that Students would have so many records (tens of millions) in the first place to warrant this performance. Take a look at that link and maybe someone else will provide a real answer to you. I am just pointing out indexes in case you are inexperienced and hadn’t worked with them.
– Brien FossFeb 27 '18 at 5:44

1 Answer
1

only runs slowly if either it is expensive to find the rows, or we get a huge number of rows and hence it is expensive to sort them.

If it is expensive to find then, then you probably need to consider indexing on TEST,MAP_IDENTIFIER. If, even with that index, the sorting cost is large, that is, you have a huge amount of rows that match the criteria, then you might want to consider adding ID to the index so that you can scan the index in a descending fashion and hence avoid the sorting cost.

Even if you do that, you must always have the ORDER BY clause. Without out, the results are always indeterminate.