Reputation: 7052
I am developing a CodeIgniter application with Mysql database which will contain lots of data.
My Query is like below
SELECT id, code, name, category, purchase_price, retail_price, expiry_date, color_code, sub_category FROM products ORDER BY id DESC
In this regard How can I make Fastest SELECT
Query ?
How can I measure Query execution time ?
Upvotes: 0
Views: 54
Reputation: 1271023
For this query:
SELECT id, code, name, category, purchase_price, retail_price, expiry_date, color_code, sub_category
FROM products
ORDER BY id DESC;
There is little you can do from an optimization perspective other than optimizing the ORDER BY
. The best index would be:
CREATE INDEX idx_products_id_desc ON products(id desc);
Upvotes: 1
Reputation: 1712
In order to make the query the absolute fastest is to limit the columns your selecting to what's absolutely necessary, id, price, color etc. Large data sets should always be server side paginated. Client side pagination is almost completely useless in the real world. Before you execute your query run:
SET profiling = 1;
After the query is finished.
SHOW PROFILES;
Upvotes: 1