Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
+ [SQL Optimization Process](/sql-optimization-concepts.md)
+ Logic Optimization
+ [Subquery Related Optimizations](/subquery-optimization.md)
+ [Column Pruning](/column-pruning.md)
+ [Decorrelation of Correlated Subquery](/correlated-subquery-optimization.md)
+ [Predicates Push Down](/predicates-push-down.md)
+ [TopN and Limit Push Down](/topn-limit-push-down.md)
Expand Down
20 changes: 20 additions & 0 deletions column-pruning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Column Pruning
summary: 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" >}}

```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](/blocklist-control-plan.md).