Skip to content

Latest commit

 

History

History
20 lines (13 loc) · 1.24 KB

column-pruning.md

File metadata and controls

20 lines (13 loc) · 1.24 KB
title summary
Column Pruning
Learn about the usage of column pruning in TiDB.

Column Pruning

The basic idea of column pruning is that for columns not used in the operator, the optimizer does not need to retain them during optimization. Removing these columns reduces the use of I/O resources and facilitates the subsequent optimization. The following is an example of column repetition:

Suppose there are four columns (a, b, c, and d) in table t. You can execute the following statement:

{{< copyable "sql" >}}

select a from t where b> 5

In this query, only column a and column b are used, and column c and column d are redundant. Regarding the query plan of this statement, the Selection operator uses column b. Then the DataSource operator uses columns a and column b. Columns c and column d can be pruned because the DataSource operator does not read them.

Therefore, when TiDB performs a top-down scanning during the logic optimization phase, redundant columns are pruned to reduce waste of resources. This scanning process is called "Column Pruning", corresponding to the columnPruner rule. If you want to disable this rule, refer to The Blocklist of Optimization Rules and Expression Pushdown.