Analyze the planned statement and find referenced tables/columns
| 44 | |
| 45 | // Analyze the planned statement and find referenced tables/columns |
| 46 | void analyze_plan(PlannedStmt* plan) |
| 47 | { |
| 48 | if (plan->permInfos == nullptr) { |
| 49 | return; |
| 50 | } |
| 51 | ListCell* lc = nullptr; |
| 52 | bool all_tables_are_deeplake = true; |
| 53 | foreach (lc, plan->permInfos) { |
| 54 | RTEPermissionInfo* perminfo = (RTEPermissionInfo*)lfirst(lc); |
| 55 | if (perminfo->relid == InvalidOid) { |
| 56 | continue; |
| 57 | } |
| 58 | auto* table_data = pg::table_storage::instance().get_table_data_if_exists(perminfo->relid); |
| 59 | if (table_data == nullptr) { |
| 60 | if (!pg::table_storage::instance().view_exists(perminfo->relid)) { |
| 61 | pg::query_info::current().set_all_tables_are_deeplake(false); |
| 62 | all_tables_are_deeplake = false; |
| 63 | } |
| 64 | continue; |
| 65 | } |
| 66 | table_data->refresh(); |
| 67 | pg::query_info::current().set_is_deeplake_table_referenced(true); |
| 68 | // Extract columns from selectedCols bitmapset |
| 69 | if (perminfo->selectedCols == nullptr) { |
| 70 | continue; |
| 71 | } |
| 72 | int32_t col = -1; |
| 73 | while ((col = bms_next_member(perminfo->selectedCols, col)) >= 0) { |
| 74 | // bms_next_member returns 0-based index, but AttrNumber is 1-based |
| 75 | // The bitmapset stores (attnum - FirstLowInvalidHeapAttributeNumber) |
| 76 | AttrNumber attnum = static_cast<AttrNumber>(col + FirstLowInvalidHeapAttributeNumber); |
| 77 | if (attnum <= 0) { // Only positive attribute numbers are real columns |
| 78 | continue; |
| 79 | } |
| 80 | auto col_idx = table_data->logical_index_for_attnum(attnum); |
| 81 | if (col_idx < 0) { |
| 82 | continue; // Dropped column or out of range |
| 83 | } |
| 84 | if (!table_data->is_column_requested(col_idx)) { |
| 85 | table_data->set_column_requested(col_idx, true); |
| 86 | if (!table_data->column_has_streamer(col_idx) && table_data->can_stream_column(col_idx)) { |
| 87 | table_data->create_streamer(col_idx, -1); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | pg::query_info::current().set_all_tables_are_deeplake(all_tables_are_deeplake); |
| 93 | } |
| 94 | |
| 95 | } // namespace pg |
| 96 |
no test coverage detected