Ask Your Question
4

What is the method of utilizing Limit in a query to search only the index column and avoid scanning all the rows?

asked 2023-06-24 11:37:34 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-24 11:50:02 +0000

pufferfish gravatar image

The method of utilizing Limit in a query to search only the index column and avoid scanning all the rows involves adding a LIMIT clause to the query. The LIMIT clause restricts the number of rows returned by the query, and can also optimize the search by limiting the scan to the indexed column only.

For example, consider a table with columns id (indexed) and name:

SELECT id FROM table_name WHERE id > 100 LIMIT 10;

In this query, the LIMIT clause restricts the result set to 10 rows, and the WHERE clause restricts the search to the indexed id column. This helps avoid scanning all the rows in the table, and instead only looks at the index to retrieve the matching rows.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-24 11:37:34 +0000

Seen: 10 times

Last updated: Jun 24 '23