Junior — Middle
Can you explain what is meant by sequential scanning of a table in a database?
sobes.tech AI
Answer from AI
Table scan is a method of reading data from a database table where the system sequentially goes through all the rows of the table without using indexes. This approach is used when:
- There is no suitable index to execute the query.
- The query requires processing a large volume of data.
The disadvantage of a table scan is that it can be slow on large tables because it requires reading all rows. For example, if a table has 1 million records and the query does not use an index, the DBMS will read all these records sequentially to find the needed data.
An example of an SQL query that might trigger a table scan:
SELECT * FROM users WHERE last_name = 'Ivanov';
If there is no index on the last_name field, a full scan of all rows in the users table will be performed.