@@ -81,11 +81,7 @@ impl ParquetTable {
81
81
)
82
82
}
83
83
84
- fn adjust_io_request (
85
- & self ,
86
- ctx : & Arc < dyn TableContext > ,
87
- projection : & Projection ,
88
- ) -> Result < usize > {
84
+ fn adjust_io_request ( & self , ctx : & Arc < dyn TableContext > , num_columns : usize ) -> Result < usize > {
89
85
let conf = GlobalConfig :: instance ( ) ;
90
86
let mut max_memory_usage = ctx. get_settings ( ) . get_max_memory_usage ( ) ? as usize ;
91
87
if conf. query . table_cache_enabled {
@@ -97,7 +93,7 @@ impl ParquetTable {
97
93
let block_file_size = 300 * 1024 * 1024_usize ;
98
94
let table_column_len = self . table_info . schema ( ) . fields ( ) . len ( ) ;
99
95
let per_column_bytes = block_file_size / table_column_len;
100
- let scan_column_bytes = per_column_bytes * projection . len ( ) ;
96
+ let scan_column_bytes = per_column_bytes * num_columns ;
101
97
let estimate_io_requests = max_memory_usage / scan_column_bytes;
102
98
103
99
let setting_io_requests = std:: cmp:: max (
@@ -115,9 +111,20 @@ impl ParquetTable {
115
111
plan : & DataSourcePlan ,
116
112
pipeline : & mut Pipeline ,
117
113
) -> Result < ( ) > {
118
- let projection = PushDownInfo :: projection_of_push_downs ( & plan. schema ( ) , & plan. push_downs ) ;
119
- let output_schema = Arc :: new ( projection. project_schema ( & plan. source_info . schema ( ) ) ) ;
120
- let max_io_requests = self . adjust_io_request ( & ctx, & projection) ?;
114
+ let columns_to_read =
115
+ PushDownInfo :: projection_of_push_downs ( & plan. schema ( ) , & plan. push_downs ) ;
116
+ let max_io_requests = self . adjust_io_request ( & ctx, columns_to_read. len ( ) ) ?;
117
+
118
+ // If there is a `PrewhereInfo`, the final output should be `PrehwereInfo.output_columns`.
119
+ // `PrewhereInfo.output_columns` should be a subset of `PushDownInfo.projection`.
120
+ let output_projection = match PushDownInfo :: prewhere_of_push_downs ( & plan. push_downs ) {
121
+ None => {
122
+ PushDownInfo :: projection_of_push_downs ( & self . table_info . schema ( ) , & plan. push_downs )
123
+ }
124
+ Some ( v) => v. output_columns . clone ( ) ,
125
+ } ;
126
+ let output_schema = Arc :: new ( output_projection. project_schema ( & plan. source_info . schema ( ) ) ) ;
127
+
121
128
let prewhere_reader = self . build_prewhere_reader ( plan) ?;
122
129
let prewhere_filter =
123
130
self . build_prewhere_filter_executor ( ctx. clone ( ) , plan, prewhere_reader. schema ( ) ) ?;
0 commit comments