0

I have a database which consists of 50 million records and I am trying to execute the following query.

SELECT q FROM q GROUP BY q ORDER BY t DESC LIMIT 100;

But, because of the size of the database, this query takes about 10 seconds to execute. So, how do I optimize this query for faster execution? How does database indexing work? I referred to this page for an answer, it suggests to use indexing but doesn't exactly tell how? I am new to this, I need a quick solution to this problem as my site is loading very slow.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • ALTER TABLE `dbName`.`tableName` DROP INDEX `newKeyName`, ADD INDEX `newKeyName` (`q`) USING BTREE; – Sumit Mar 01 '18 at 07:35

1 Answers1

1

By this way you can create Index.

Alter table q
add key(q),
add key(t);
vinieth
  • 1,204
  • 3
  • 16
  • 34