MySQL Example Scripts for “Partial Results”


This section contains the create and insert statements to run the examples from Chapter 7, “Partial Results” in a MySQL database.

Querying Top-N Rows

An indexed Top-N query doesn’t show a “filesort” operation in the Extras column:

SELECT *
  FROM sales
 ORDER BY sale_date DESC
 LIMIT 10;

+----+-------+-------+-------------+--------+-------+
| id | table | type  | key         | rows   | Extra |
+----+-------+-------+-------------+--------+-------+
|  1 | sales | index | sales_dt_pr | 836092 |       | 
+----+-------+-------+-------------+--------+-------+

About the Author

As an author, trainer, and coach Markus Winand specializes in helping developers cope with SQL performance issues. He also published the book SQL Performance Explained and tweets his best performance tips via @SQLPerfTips.http://winand.at/

Recent Questions at Ask.Use-The-Index-Luke.com

0
votes
1
answer
150
views

We want to buy the book but I can't

Jul 18 at 21:36 Markus Winand ♦♦ 541
book
0
votes
2
answers
159
views
0
votes
0
answers
824
views

Performance very bad in Postgresql 9.3

Jul 08 at 11:54 Markus Winand ♦♦ 541
performance issue