Avoiding full table scans in MySQL

How can I avoid a full table scan on mysql?

+3
source share
4 answers

In general, making sure that you have a useful index for the fields that appear in the sections WHERE, JOINand ORDER BY.

+12
source

Index your data.

Write queries that use these indexes.

Anything else we need.

+5
source

, , .. ... .

+1

Use the LIMIT clause when you know how many rows you expect to return, for example, if you are looking for a record with a known identification field that is unique, limit your selection to 1, so mysql will stop searching after it finds the first record. The same goes for updates and deletions.

SELECT * FROM `yourTable` WHERE `idField` = 123 LIMIT 1
0
source

Source: https://habr.com/ru/post/1773079/


All Articles