Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do the costs of I/O operations differ between index scans and table scans


How do the costs of I/O operations differ between index scans and table scans


The costs of I/O operations differ between index scans and table scans in several ways:

Index Scan

1. Cost of I/O Operations: Index scans are generally more efficient in terms of I/O operations. They only need to read the index, which is typically smaller than the entire table, resulting in fewer disk accesses.

2. I/O Cost: The I/O cost for an index scan is typically lower because the index is more compact and can be read more quickly.

3. CPU Cost: The CPU cost for an index scan is typically lower because the index is more organized and can be searched more efficiently.

4. Total Operator Cost: The total operator cost for an index scan is typically lower because it includes the I/O and CPU costs.

Table Scan

1. Cost of I/O Operations: Table scans are generally less efficient in terms of I/O operations. They need to read the entire table, which can result in more disk accesses.

2. I/O Cost: The I/O cost for a table scan is typically higher because the table is larger and requires more disk accesses.

3. CPU Cost: The CPU cost for a table scan is typically higher because the table is larger and requires more processing.

4. Total Operator Cost: The total operator cost for a table scan is typically higher because it includes the I/O and CPU costs.

Conclusion

In summary, index scans are generally more efficient in terms of I/O operations and CPU usage compared to table scans. However, the choice between the two depends on the specific requirements and constraints of the query and the database.

Citations:
[1] https://www.ibm.com/docs/en/db2/11.5?topic=methods-data-access-through-index-scans
[2] https://stackoverflow.com/questions/8702905/table-scan-and-index-scan-in-sql
[3] https://dba.stackexchange.com/questions/250474/shouldnt-operator-cost-at-least-be-as-large-as-i-o-or-cpu-cost-that-comprises-i
[4] https://forums.oracle.com/ords/r/apexds/community/q?question=cost-of-a-full-table-scan-is-less-than-an-index-unique-scan-1453
[5] https://venkatsqlinterview.blogspot.com/2011/05/difference-between-index-scan-and-index.html