diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c index ebe8cb587bd..50a77a03704 100644 --- a/src/backend/access/aocs/aocsam_handler.c +++ b/src/backend/access/aocs/aocsam_handler.c @@ -590,12 +590,14 @@ extractcolumns_from_node(Node *expr, bool *cols, AttrNumber natts) } static TableScanDesc -aoco_beginscan_extractcolumns(Relation rel, Snapshot snapshot, ParallelTableScanDesc parallel_scan, - List *targetlist, List *qual, - uint32 flags) +aoco_beginscan_extractcolumns(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, + ParallelTableScanDesc parallel_scan, + PlanState *ps, uint32 flags) { AOCSScanDesc aoscan; AttrNumber natts = RelationGetNumberOfAttributes(rel); + List *targetlist = ps->plan->targetlist; + List *qual = ps->plan->qual; bool *cols; bool found = false; @@ -620,6 +622,9 @@ aoco_beginscan_extractcolumns(Relation rel, Snapshot snapshot, ParallelTableScan pfree(cols); + if (gp_enable_predicate_pushdown) + ps->qual = aocs_predicate_pushdown_prepare(aoscan, qual, ps->qual, ps->ps_ExprContext, ps); + return (TableScanDesc)aoscan; } diff --git a/src/backend/access/appendonly/appendonlyam.c b/src/backend/access/appendonly/appendonlyam.c index e90bd2093cb..1c56ae0b946 100755 --- a/src/backend/access/appendonly/appendonlyam.c +++ b/src/backend/access/appendonly/appendonlyam.c @@ -1663,6 +1663,18 @@ appendonly_beginscan(Relation relation, return (TableScanDesc) aoscan; } +TableScanDesc +appendonly_beginscan_extractcolumns(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, + ParallelTableScanDesc parallel_scan, + PlanState *ps, uint32 flags) +{ + AppendOnlyScanDesc aoscan; + aoscan = (AppendOnlyScanDesc) appendonly_beginscan(rel, snapshot, nkeys, key, parallel_scan, flags); + if (gp_enable_predicate_pushdown) + ps->qual = appendonly_predicate_pushdown_prepare(aoscan, ps->qual, ps->ps_ExprContext); + return (TableScanDesc) aoscan; +} + /* ---------------- * appendonly_rescan - restart a relation scan * diff --git a/src/backend/access/appendonly/appendonlyam_handler.c b/src/backend/access/appendonly/appendonlyam_handler.c index 8574d702eba..1916c452283 100644 --- a/src/backend/access/appendonly/appendonlyam_handler.c +++ b/src/backend/access/appendonly/appendonlyam_handler.c @@ -2327,6 +2327,11 @@ static const TableAmRoutine ao_row_methods = { .slot_callbacks = appendonly_slot_callbacks, + /* + * appendonly row table doesn't extract columns, but handles + * predicate pushdown. + */ + .scan_begin_extractcolumns = appendonly_beginscan_extractcolumns, .scan_begin = appendonly_beginscan, .scan_end = appendonly_endscan, .scan_rescan = appendonly_rescan, diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index 60939ec7538..b8e82f87a31 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -100,9 +100,9 @@ SeqNext(SeqScanState *node) /* try parallel mode for AOCO extract columns */ scandesc = table_beginscan_es(node->ss.ss_currentRelation, estate->es_snapshot, + 0, NULL, pscan, - node->ss.ps.plan->targetlist, - node->ss.ps.plan->qual); + &node->ss.ps); } else { @@ -120,31 +120,11 @@ SeqNext(SeqScanState *node) */ scandesc = table_beginscan_es(node->ss.ss_currentRelation, estate->es_snapshot, + 0, NULL, NULL, - node->ss.ps.plan->targetlist, - node->ss.ps.plan->qual); + &node->ss.ps); node->ss.ss_currentScanDesc = scandesc; } - if (gp_enable_predicate_pushdown) - { - if (RelationIsAoRows(node->ss.ss_currentRelation)) - { - /* eval predicate push down */ - node->ss.ps.qual = - appendonly_predicate_pushdown_prepare((AppendOnlyScanDesc)node->ss.ss_currentScanDesc, - node->ss.ps.qual, - node->ss.ps.ps_ExprContext); - } - else if (RelationIsAoCols(node->ss.ss_currentRelation)) - { - node->ss.ps.qual = - aocs_predicate_pushdown_prepare((AOCSScanDesc)node->ss.ss_currentScanDesc, - node->ss.ps.plan->qual, - node->ss.ps.qual, - node->ss.ps.ps_ExprContext, - &node->ss.ps); - } - } } /* diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index d9a3b37e9d3..61c13537c3c 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -254,6 +254,13 @@ typedef void (*IndexBuildCallback) (Relation index, bool tupleIsAlive, void *state); +/* + * CBDB: Execution structure shouldn't appear here in PG design. We need to + * tell the scan node to do low-level and efficient filtering. The scan node + * will use low-level APIs exposed by the storage. + */ +struct PlanState; + /* * API struct for a table AM. Note this must be allocated in a * server-lifetime manner, typically as a static const struct, which then gets @@ -315,9 +322,9 @@ typedef struct TableAmRoutine */ TableScanDesc (*scan_begin_extractcolumns) (Relation rel, Snapshot snapshot, + int nkeys, struct ScanKeyData *key, ParallelTableScanDesc parallel_scan, - List *targetlist, - List *qual, + struct PlanState *ps, uint32 flags); /* @@ -925,8 +932,10 @@ table_beginscan(Relation rel, Snapshot snapshot, * Like table_beginscan_parallel, it will be parallel mode if parallel_scan is not NULL. */ static inline TableScanDesc -table_beginscan_es(Relation relation, Snapshot snapshot, ParallelTableScanDesc parallel_scan, - List *targetList, List *qual) +table_beginscan_es(Relation relation, Snapshot snapshot, + int nkeys, struct ScanKeyData *key, + ParallelTableScanDesc parallel_scan, + struct PlanState *ps) { bool isParallel = parallel_scan != NULL; uint32 flags = SO_TYPE_SEQSCAN | @@ -951,12 +960,13 @@ table_beginscan_es(Relation relation, Snapshot snapshot, ParallelTableScanDesc p } if (relation->rd_tableam->scan_begin_extractcolumns) - return relation->rd_tableam->scan_begin_extractcolumns(relation, snapshot, parallel_scan, - targetList, qual, - flags); + return relation->rd_tableam->scan_begin_extractcolumns(relation, snapshot, + nkeys, key, + parallel_scan, + ps, flags); return relation->rd_tableam->scan_begin(relation, snapshot, - 0, NULL, + nkeys, key, parallel_scan, flags); } diff --git a/src/include/cdb/cdbappendonlyam.h b/src/include/cdb/cdbappendonlyam.h index 10369ec7555..f060cabb6d2 100644 --- a/src/include/cdb/cdbappendonlyam.h +++ b/src/include/cdb/cdbappendonlyam.h @@ -432,6 +432,12 @@ extern TableScanDesc appendonly_beginscan(Relation relation, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags); +extern TableScanDesc appendonly_beginscan_extractcolumns(Relation rel, + Snapshot snapshot, + int nkeys, struct ScanKeyData *key, + ParallelTableScanDesc parallel_scan, + PlanState *ps, + uint32 flags); extern void appendonly_rescan(TableScanDesc scan, ScanKey key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode);