[Bug] reject_partition_fullscan does not reject full scans planned by GPORCA, and threshold 0 rejects partial scans under the planner
Mantenedores costumam responder em até 2 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 44/100
Direção de pesquisa
Start by reading gpcontrib/reject_partition_fullscan and the partition_fullscan_reject regression SQL; the issue says its expected output is missing. Trace check_dynamic_scan_fullscan() and check_append_no_pruneinfo() to understand the GPORCA range table and planner pruning cases. Add regression coverage for full and partial scans with both optimizers and threshold 0; done means the full scan is rejected consistently while the documented partial scan remains allowed.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Apache Cloudberry version
Reproduced on:
REL_2_STABLEat 91582af9baf (PostgreSQL 14.12, 2.2.0-incubating build dev)mainat eb9bf338855 (PostgreSQL 16.9, 3.0.0-devel)
What happened
gpcontrib/reject_partition_fullscan (added in #1713) behaves differently depending on the optimizer.
- GPORCA (the default optimizer): full scans are not rejected. A
SELECTthat scans all
partitions (Dynamic Seq Scan, "Number of partitions to scan: 3 (out of 3)") runs normally.
The dynamic scan has nopart_prune_info, so the walker callscheck_dynamic_scan_fullscan()as
intended, but that function returns early at
rte->relkind != RELKIND_PARTITIONED_TABLE: in the range table that GPORCA produces, the entry
of the partitioned table hasrelkindunset.debug_print_planfor the query below shows
:relid 17047 :relkind <>with GPORCA, and:relid 17047 :relkind pwith the Postgres-based
planner.UPDATEandDELETEon partitioned tables are planned by the Postgres-based planner
and are rejected as expected. - Postgres-based planner with
partition_fullscan_threshold = 0: partial scans are rejected.
The source comment and the GUC description say that0rejects only true full scans. For a
plannerAppendwithoutPartitionPruneInfo(pruning done at plan time),check_append_no_pruneinfo()
rejects whenever more than one partition remains, so a range filter that keeps 2 of 3 partitions
fails with "2 partitions would be scanned".
What you think should happen instead
- A full partition scan should be rejected regardless of the optimizer.
- With
partition_fullscan_threshold = 0, only scans of all partitions should be rejected,
as documented, or the documentation of0should be changed to match the behavior.
How to reproduce
LOAD 'reject_partition_fullscan';
CREATE TABLE pfr (id int, dt date) PARTITION BY RANGE (dt) DISTRIBUTED BY (id);
CREATE TABLE pfr_p1 PARTITION OF pfr FOR VALUES FROM ('2025-01-01') TO ('2025-04-01');
CREATE TABLE pfr_p2 PARTITION OF pfr FOR VALUES FROM ('2025-04-01') TO ('2025-07-01');
CREATE TABLE pfr_p3 PARTITION OF pfr FOR VALUES FROM ('2025-07-01') TO ('2025-10-01');
INSERT INTO pfr SELECT g, '2025-01-01'::date + (g % 270) FROM generate_series(1, 3000) g;
ANALYZE pfr;
-- defaults: reject_partition_fullscan = on, partition_fullscan_threshold = 0
SET optimizer = on;
EXPLAIN (COSTS OFF) SELECT count(*) FROM pfr;
SELECT count(*) FROM pfr; -- expected: rejected
SET optimizer = off;
SELECT count(*) FROM pfr; -- rejected (correct)
SELECT count(*) FROM pfr WHERE dt = '2025-02-01'; -- allowed (correct)
SELECT count(*) FROM pfr WHERE dt >= '2025-01-01' AND dt < '2025-07-01'; -- expected: allowed
Output (identical on both branches):
SET optimizer = on;
EXPLAIN (COSTS OFF) SELECT count(*) FROM pfr;
Finalize Aggregate
-> Gather Motion 3:1 (slice1; segments: 3)
-> Partial Aggregate
-> Dynamic Seq Scan on pfr
Number of partitions to scan: 3 (out of 3)
Optimizer: GPORCA
SELECT count(*) FROM pfr;
count
-------
3000
SET optimizer = off;
SELECT count(*) FROM pfr;
ERROR: partitioned table "public.pfr" full partition scan is not allowed, 3 partitions would be scanned
SELECT count(*) FROM pfr WHERE dt = '2025-02-01';
count
-------
11
SELECT count(*) FROM pfr WHERE dt >= '2025-01-01' AND dt < '2025-07-01';
ERROR: partitioned table "public.pfr" full partition scan is not allowed, 2 partitions would be scanned
Operating System
Rocky Linux 9.7 (apache/incubator-cloudberry:cbdb-build-rocky9-latest), built with devops/build/automation/cloudberry/scripts.
Anything else
Candidate fix for item 1 (tested on REL_2_STABLE only): look the relkind up from the catalog
instead of trusting the range table entry, in both places that check it:
- rte->relkind == RELKIND_PARTITIONED_TABLE)
+ get_rel_relkind(rte->relid) == RELKIND_PARTITIONED_TABLE)
...
- rte->relkind != RELKIND_PARTITIONED_TABLE)
+ get_rel_relkind(rte->relid) != RELKIND_PARTITIONED_TABLE)
With this change and GPORCA on, SELECT count(*) FROM pfr is rejected ("3 partitions would be
scanned"), a filter that keeps one partition is allowed, a filter that keeps 2 of 3 partitions is
allowed with threshold 0 and with threshold 2, and an unfiltered query is rejected with
threshold 2. Results under the Postgres-based planner do not change. Item 2 is not addressed by
this change.
The module's Makefile declares REGRESS = partition_fullscan_reject, but there is no
expected/ directory, so the regression test cannot pass and none of the behavior above is
covered. The test SQL does not exercise GPORCA dynamic scans with static pruning.
Bug found by Claude Code. Please review it again.
- Linguagem predominante
- C
- Estrelas
- 1.4k
- Forks
- 273
- Merge médio
- 4d 6h
- PRs com merge (30d)
- 105
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de apache/cloudberry
-
isolation2 lockmodes fails on cassert builds: extra AccessShareLock on partition rootTalvez já em andamento @tuhaihe assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apache/cloudberry#2356 ·
Mantenedores costumam responder em até 2 dias
-
psql tab completion broken for storage servers, tags, profiles and resource groups (pre-PG15 query format)Talvez já em andamento @allenvox assumiu há 5 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
apache/cloudberry#2316 ·
Mantenedores costumam responder em até 2 dias
-
[Bug] Expand fails to recognize user-defined tablespacesTalvez já em andamento @nix-oss assumiu há 93 dias. Abertatype: Bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
apache/cloudberry#1885 · 2 reações ·
Mantenedores costumam responder em até 2 dias
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Talvez já em andamento @talmacschen-arch assumiu há 154 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
apache/cloudberry#1825 ·
Mantenedores costumam responder em até 2 dias
-
type: Bug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 53/100
apache/cloudberry#2350 · 1 reação ·
Mantenedores costumam responder em até 2 dias
Todas as issues de apache/cloudberry
Issues semelhantes
-
`sha256()` returns a wrong hash when libsql-ffi is built with gcc 11 or laterTalvez já em andamento @colinhacks assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
tursodatabase/libsql#2333 ·
Mantenedores costumam responder em até 11 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
OpenPrinting/cups#1826 ·
Mantenedores costumam responder em até 1 dia
-
Backport to 3.0 advertises a suffix that does not existTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
389ds/389-ds-base#8152 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
RetroAchievements/rcheevos#580 · 1 comentário ·
Mantenedores costumam responder em até 5 dias