Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions tsl/src/nodes/columnar_scan/columnar_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,27 @@ ts_columnar_scan_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, const
chunk_rel->pathlist = NIL;
chunk_rel->partial_pathlist = NIL;

/*
* We want to consider startup costs so that IndexScan is preferred to
* sorted SeqScan when we may have a chance to use SkipScan. We consider
* startup costs for LIMIT queries, and SkipScan is basically a
* "LIMIT 1" query run "ndistinct" times. At this point we don't have
* all information to check if SkipScan can be used, but we can narrow
* it down.
*
* First, check if this query is candidate for SELECT DISTINCT SkipScan.
*/
const bool potential_select_distinct = list_length(root->distinct_pathkeys) >= 1;

/* Next, candidate for DISTINCT aggregate SkipScan */
const bool potential_distinct_aggregate =
root->numOrderedAggs >= 1 && list_length(root->group_pathkeys) == 1;

if (potential_select_distinct || potential_distinct_aggregate)
{
chunk_rel->consider_startup = true;
}

/* add RangeTblEntry and RelOptInfo for compressed chunk */
columnar_scan_add_plannerinfo(root,
compression_info,
Expand All @@ -1193,8 +1214,6 @@ ts_columnar_scan_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, const

RelOptInfo *compressed_rel = compression_info->compressed_rel;

compressed_rel->consider_parallel = chunk_rel->consider_parallel;

/* translate chunk_rel->baserestrictinfo */
if (ts_guc_enable_columnar_scan_filter_pushdown)
{
Expand Down Expand Up @@ -1267,25 +1286,6 @@ ts_columnar_scan_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, const
&sort_info,
compression_info);

/*
* We want to consider startup costs so that IndexScan is preferred to
* sorted SeqScan when we may have a chance to use SkipScan. We consider
* startup costs for LIMIT queries, and SkipScan is basically a
* "LIMIT 1" query run "ndistinct" times. At this point we don't have
* all information to check if SkipScan can be used, but we can narrow
* it down.
*/
if (!chunk_rel->consider_startup && IsA(compressed_path, IndexPath))
{
/* Candidate for SELECT DISTINCT SkipScan */
if (list_length(root->distinct_pathkeys) == 1
/* Candidate for DISTINCT aggregate SkipScan */
|| (root->numOrderedAggs >= 1 && list_length(root->group_pathkeys) == 1))
{
chunk_rel->consider_startup = true;
}
}

/*
* Add the paths to the chunk relation.
*/
Expand Down Expand Up @@ -2404,6 +2404,9 @@ columnar_scan_add_plannerinfo(PlannerInfo *root, CompressionInfo *info, const Ch
/* translate chunk_rel->joininfo for compressed_rel */
compressed_rel_setup_joininfo(compressed_rel, info);

compressed_rel->consider_parallel = chunk_rel->consider_parallel;
compressed_rel->consider_startup = chunk_rel->consider_startup;

/*
* Force parallel plan creation, see compute_parallel_worker().
* This is not compatible with ts_classify_relation(), but on the other hand
Expand Down
4 changes: 4 additions & 0 deletions tsl/test/expected/skip_scan.out
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,10 @@ psql:include/skip_scan_multi_query.sql:44: INFO: SkipScan used on compress_hype
psql:include/skip_scan_multi_query.sql:44: INFO: SkipScan used on compress_hyper_9_76_chunk_status_region_dev_dev_name__ts_me_idx(region NOT NULL, dev NOT NULL)
-- RowCompareExpr
:PREFIX SELECT DISTINCT ON (status, dev) * FROM :TABLE WHERE region = 'reg_1' and (status, dev) > (1,2);
psql:include/skip_scan_multi_query.sql:47: INFO: SkipScan used on compress_hyper_9_73_chunk_status_region_dev_dev_name__ts_me_idx(status NOT NULL, dev NOT NULL)
psql:include/skip_scan_multi_query.sql:47: INFO: SkipScan used on compress_hyper_9_74_chunk_status_region_dev_dev_name__ts_me_idx(status NOT NULL, dev NOT NULL)
psql:include/skip_scan_multi_query.sql:47: INFO: SkipScan used on compress_hyper_9_75_chunk_status_region_dev_dev_name__ts_me_idx(status NOT NULL, dev NOT NULL)
psql:include/skip_scan_multi_query.sql:47: INFO: SkipScan used on compress_hyper_9_76_chunk_status_region_dev_dev_name__ts_me_idx(status NOT NULL, dev NOT NULL)
-- always false expr similar to our initial skip qual
:PREFIX SELECT DISTINCT ON (status, region, dev) * FROM :TABLE WHERE dev > NULL and status > NULL and region > NULL;
-- no tuples matching
Expand Down
Loading