Skip to content

Commit 7c0423c

Browse files
authored
feature: Use amflags to support Column-oriented scanning of custom tableam (#407)
For custom tableam, maybe it support column-oriented scanning, the postgres planner can no longer use whether am_handler is aocs handler to decide whether only to add the columns required by the operator to the targetlist, but use amflags to determine If table am supports column-oriented scanning, the flags returned by set_flags will set the SCAN_SUPPORT_COLUMN_ORIENTED_SCAN bit. Co-authored-by: GongXun <gongxun@hashdata.cn>
1 parent be6897c commit 7c0423c

5 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/backend/access/aocs/aocsam_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ aoco_getnextslot(TableScanDesc scan, ScanDirection direction, TupleTableSlot *sl
760760
static uint32
761761
aoco_scan_flags(Relation rel)
762762
{
763-
return 0;
763+
return SCAN_SUPPORT_COLUMN_ORIENTED_SCAN;
764764
}
765765

766766
static Size

src/backend/optimizer/plan/createplan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ use_physical_tlist(PlannerInfo *root, Path *path, int flags)
974974
* Using physical target list with column store will result in scanning all
975975
* column files, which will cause a significant performance degradation.
976976
*/
977-
if (AMHandlerIsAoCols(rel->amhandler))
977+
if (rel->amflags & AMFLAG_HAS_COLUMN_ORIENTED_SCAN)
978978
return false;
979979

980980
/*

src/backend/optimizer/util/plancat.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
491491
relation->rd_tableam->scan_getnextslot_tidrange != NULL)
492492
rel->amflags |= AMFLAG_HAS_TID_RANGE;
493493

494+
/* Collect info about relation's store information, if it support column-oriented scan */
495+
if (relation->rd_tableam && relation->rd_tableam->scan_flags &&
496+
(relation->rd_tableam->scan_flags(relation) & SCAN_SUPPORT_COLUMN_ORIENTED_SCAN)) {
497+
rel->amflags |= AMFLAG_HAS_COLUMN_ORIENTED_SCAN;
498+
}
499+
494500
/*
495501
* Collect info about relation's partitioning scheme, if any. Only
496502
* inheritance parents may be partitioned.

src/include/access/tableam.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ struct TBMIterateResult;
4141
struct VacuumParams;
4242
struct ValidateIndexState;
4343

44+
/**
45+
* Flags represented the supported features of scan.
46+
*
47+
* The first 8 bits are reserved for kernel expansion of some attributes,
48+
* and the remaining 24 bits are reserved for custom tableam.
49+
*
50+
* If you add a new flag, make sure the flag's bit is consecutive with
51+
* the previous one.
52+
*
53+
*/
54+
#define SCAN_SUPPORT_COLUMN_ORIENTED_SCAN (1 << 0) /* support column-oriented scanning*/
55+
4456
/*
4557
* Bitmask values for the flags argument to the scan_begin callback.
4658
*/

src/include/nodes/pathnodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ static inline void planner_subplan_put_plan(struct PlannerInfo *root, SubPlan *s
823823

824824
/* Bitmask of flags supported by table AMs */
825825
#define AMFLAG_HAS_TID_RANGE (1 << 0)
826+
/* Column-oriented scanning of flags supported by table AMs */
827+
#define AMFLAG_HAS_COLUMN_ORIENTED_SCAN (1 << 1)
826828

827829
typedef enum RelOptKind
828830
{

0 commit comments

Comments
 (0)