1111#include " duckdb/main/client_config.hpp"
1212#include " duckdb/optimizer/matcher/expression_matcher.hpp"
1313#include " duckdb/planner/expression/bound_between_expression.hpp"
14- #include " duckdb/planner/expression_iterator.hpp"
1514#include " duckdb/planner/operator/logical_get.hpp"
1615#include " duckdb/storage/data_table.hpp"
1716#include " duckdb/storage/table/scan_state.hpp"
@@ -71,7 +70,8 @@ class TableScanGlobalState : public GlobalTableFunctionState {
7170 TableScanGlobalState (ClientContext &context, const FunctionData *bind_data_p) {
7271 D_ASSERT (bind_data_p);
7372 auto &bind_data = bind_data_p->Cast <TableScanBindData>();
74- max_threads = bind_data.table .GetStorage ().MaxThreads (context);
73+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
74+ max_threads = duck_table.GetStorage ().MaxThreads (context);
7575 }
7676
7777 // ! The maximum number of threads for this table scan.
@@ -130,8 +130,9 @@ class DuckIndexScanState : public TableScanGlobalState {
130130
131131 void TableScanFunc (ClientContext &context, TableFunctionInput &data_p, DataChunk &output) override {
132132 auto &bind_data = data_p.bind_data ->Cast <TableScanBindData>();
133- auto &tx = DuckTransaction::Get (context, bind_data.table .catalog );
134- auto &storage = bind_data.table .GetStorage ();
133+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
134+ auto &tx = DuckTransaction::Get (context, duck_table.catalog );
135+ auto &storage = duck_table.GetStorage ();
135136 auto &l_state = data_p.local_state ->Cast <IndexScanLocalState>();
136137
137138 auto row_id_count = row_ids.size ();
@@ -216,7 +217,8 @@ class DuckTableScanState : public TableScanGlobalState {
216217
217218 l_state->scan_state .Initialize (std::move (storage_ids), input.filters .get (), input.sample_options .get ());
218219
219- auto &storage = bind_data.table .GetStorage ();
220+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
221+ auto &storage = duck_table.GetStorage ();
220222 storage.NextParallelScan (context.client , state, l_state->scan_state );
221223 if (input.CanRemoveFilterColumns ()) {
222224 l_state->all_columns .Initialize (context.client , scanned_types);
@@ -228,8 +230,9 @@ class DuckTableScanState : public TableScanGlobalState {
228230
229231 void TableScanFunc (ClientContext &context, TableFunctionInput &data_p, DataChunk &output) override {
230232 auto &bind_data = data_p.bind_data ->Cast <TableScanBindData>();
231- auto &tx = DuckTransaction::Get (context, bind_data.table .catalog );
232- auto &storage = bind_data.table .GetStorage ();
233+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
234+ auto &tx = DuckTransaction::Get (context, duck_table.catalog );
235+ auto &storage = duck_table.GetStorage ();
233236
234237 auto &l_state = data_p.local_state ->Cast <TableScanLocalState>();
235238 l_state.scan_state .options .force_fetch_row = ClientConfig::GetConfig (context).force_fetch_row ;
@@ -258,7 +261,8 @@ class DuckTableScanState : public TableScanGlobalState {
258261
259262 double TableScanProgress (ClientContext &context, const FunctionData *bind_data_p) const override {
260263 auto &bind_data = bind_data_p->Cast <TableScanBindData>();
261- auto &storage = bind_data.table .GetStorage ();
264+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
265+ auto &storage = duck_table.GetStorage ();
262266 auto total_rows = storage.GetTotalRows ();
263267
264268 // The table is empty or smaller than the standard vector size.
@@ -306,7 +310,8 @@ unique_ptr<GlobalTableFunctionState> DuckTableScanInitGlobal(ClientContext &cont
306310 }
307311
308312 g_state->projection_ids = input.projection_ids ;
309- const auto &columns = bind_data.table .GetColumns ();
313+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
314+ const auto &columns = duck_table.GetColumns ();
310315 for (const auto &col_idx : input.column_indexes ) {
311316 if (col_idx.IsRowIdColumn ()) {
312317 g_state->scanned_types .emplace_back (LogicalType::ROW_TYPE);
@@ -327,14 +332,15 @@ unique_ptr<GlobalTableFunctionState> DuckIndexScanInitGlobal(ClientContext &cont
327332 }
328333 g_state->finished = g_state->row_ids .empty () ? true : false ;
329334
330- auto &local_storage = LocalStorage::Get (context, bind_data.table .catalog );
335+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
336+ auto &local_storage = LocalStorage::Get (context, duck_table.catalog );
331337 g_state->table_scan_state .options .force_fetch_row = ClientConfig::GetConfig (context).force_fetch_row ;
332338
333339 if (input.CanRemoveFilterColumns ()) {
334340 g_state->projection_ids = input.projection_ids ;
335341 }
336342
337- const auto &columns = bind_data. table .GetColumns ();
343+ const auto &columns = duck_table .GetColumns ();
338344 for (const auto &col_idx : input.column_indexes ) {
339345 g_state->column_ids .push_back (GetStorageIndex (bind_data.table , col_idx));
340346 if (col_idx.IsRowIdColumn ()) {
@@ -467,8 +473,8 @@ unique_ptr<GlobalTableFunctionState> TableScanInitGlobal(ClientContext &context,
467473 D_ASSERT (input.bind_data );
468474
469475 auto &bind_data = input.bind_data ->Cast <TableScanBindData>();
470- auto &table = bind_data.table ;
471- auto &storage = table .GetStorage ();
476+ auto &duck_table = bind_data.table . Cast <DuckTableEntry>() ;
477+ auto &storage = duck_table .GetStorage ();
472478
473479 // Can't index scan without filters.
474480 if (!input.filters ) {
@@ -502,7 +508,7 @@ unique_ptr<GlobalTableFunctionState> TableScanInitGlobal(ClientContext &context,
502508 auto total_rows_from_percentage = LossyNumericCast<idx_t >(double (total_rows) * scan_percentage);
503509 auto max_count = MaxValue (scan_max_count, total_rows_from_percentage);
504510
505- auto &column_list = table .GetColumns ();
511+ auto &column_list = duck_table .GetColumns ();
506512 bool index_scan = false ;
507513 unsafe_vector<row_t > row_ids;
508514
@@ -520,13 +526,14 @@ unique_ptr<GlobalTableFunctionState> TableScanInitGlobal(ClientContext &context,
520526static unique_ptr<BaseStatistics> TableScanStatistics (ClientContext &context, const FunctionData *bind_data_p,
521527 column_t column_id) {
522528 auto &bind_data = bind_data_p->Cast <TableScanBindData>();
523- auto &local_storage = LocalStorage::Get (context, bind_data.table .catalog );
529+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
530+ auto &local_storage = LocalStorage::Get (context, duck_table.catalog );
524531
525532 // Don't emit statistics for tables with outstanding transaction-local data.
526- if (local_storage.Find (bind_data. table .GetStorage ())) {
533+ if (local_storage.Find (duck_table .GetStorage ())) {
527534 return nullptr ;
528535 }
529- return bind_data. table .GetStatistics (context, column_id);
536+ return duck_table .GetStatistics (context, column_id);
530537}
531538
532539static void TableScanFunc (ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
@@ -552,7 +559,8 @@ OperatorPartitionData TableScanGetPartitionData(ClientContext &context, TableFun
552559vector<PartitionStatistics> TableScanGetPartitionStats (ClientContext &context, GetPartitionStatsInput &input) {
553560 auto &bind_data = input.bind_data ->Cast <TableScanBindData>();
554561 vector<PartitionStatistics> result;
555- auto &storage = bind_data.table .GetStorage ();
562+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
563+ auto &storage = duck_table.GetStorage ();
556564 return storage.GetPartitionStats (context);
557565}
558566
@@ -568,10 +576,11 @@ void TableScanDependency(LogicalDependencyList &entries, const FunctionData *bin
568576
569577unique_ptr<NodeStatistics> TableScanCardinality (ClientContext &context, const FunctionData *bind_data_p) {
570578 auto &bind_data = bind_data_p->Cast <TableScanBindData>();
571- auto &local_storage = LocalStorage::Get (context, bind_data.table .catalog );
572- auto &storage = bind_data.table .GetStorage ();
579+ auto &duck_table = bind_data.table .Cast <DuckTableEntry>();
580+ auto &local_storage = LocalStorage::Get (context, duck_table.catalog );
581+ auto &storage = duck_table.GetStorage ();
573582 idx_t table_rows = storage.GetTotalRows ();
574- idx_t estimated_cardinality = table_rows + local_storage.AddedRows (bind_data. table .GetStorage ());
583+ idx_t estimated_cardinality = table_rows + local_storage.AddedRows (duck_table .GetStorage ());
575584 return make_uniq<NodeStatistics>(table_rows, estimated_cardinality);
576585}
577586
0 commit comments