[Bug] GPORCA ignores foreign segments of a postgres_fdw table and returns duplicated rows
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by comparing GPORCA's handling of postgres_fdw foreign segments with the Postgres-based planner path, focusing on the foreign scan and gp_foreign_server behavior described in the issue. Reproduce with the provided SQL on a three-primary demo cluster, then inspect the optimizer code and tests for foreign tables with mpp_execute 'all segments'. Done means GPORCA returns one scan per foreign segment with correct server OIDs, or falls back to the Postgres planner.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
A postgres_fdw foreign table with mpp_execute 'all segments' that has several foreign
segments (ADD FOREIGN SEGMENT FROM SERVER ... INTO ..., added in #320) is scanned correctly by
the Postgres-based planner: one executor per foreign server. With GPORCA, which is the default
optimizer, the foreign segments are ignored. The table is scanned on all segments of the
cluster, so some remote servers are read more than once and rows are duplicated.
gp_foreign_server is 0 for every row.
What you think should happen instead
GPORCA should produce the same plan shape as the Postgres-based planner: one scan per foreign
segment, each reading its own server, with gp_foreign_server set to that server's OID. If
GPORCA cannot support foreign segments, it should fall back to the Postgres-based planner
instead of returning wrong results.
How to reproduce
Demo cluster with 3 primaries. The remote servers are two databases on the same cluster.
CREATE DATABASE bugfdw1;
CREATE DATABASE bugfdw2;
\c bugfdw1
CREATE TABLE t1 (a int, b text) DISTRIBUTED BY (a);
INSERT INTO t1 SELECT g, 'bugfdw1' FROM generate_series(1, 10) g;
\c bugfdw2
CREATE TABLE t1 (a int, b text) DISTRIBUTED BY (a);
INSERT INTO t1 SELECT g, 'bugfdw2' FROM generate_series(1, 10) g;
CREATE DATABASE bugrepro;
\c bugrepro
CREATE EXTENSION postgres_fdw;
CREATE SERVER mpps1 FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '127.0.0.1', port '7000', dbname 'bugfdw1');
CREATE SERVER mpps2 FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '127.0.0.1', port '7000', dbname 'bugfdw2');
CREATE USER MAPPING FOR CURRENT_USER SERVER mpps1;
CREATE USER MAPPING FOR CURRENT_USER SERVER mpps2;
CREATE FOREIGN TABLE fs1 (a int, b text) SERVER mpps1
OPTIONS (table_name 't1', mpp_execute 'all segments');
ADD FOREIGN SEGMENT FROM SERVER mpps1 INTO fs1;
ADD FOREIGN SEGMENT FROM SERVER mpps2 INTO fs1;
SET optimizer = off;
EXPLAIN (COSTS OFF) SELECT * FROM fs1;
SELECT gp_foreign_server, b, count(*) FROM fs1 GROUP BY 1, 2 ORDER BY 1, 2;
SET optimizer = on;
EXPLAIN (COSTS OFF) SELECT * FROM fs1;
SELECT gp_foreign_server, b, count(*) FROM fs1 GROUP BY 1, 2 ORDER BY 1, 2;
Postgres-based planner (correct):
Gather Motion 2:1 (slice1; segments: 2)
-> Foreign Scan on fs1
Optimizer: Postgres query optimizer
gp_foreign_server | b | count
-------------------+---------+-------
17040 | bugfdw1 | 10
17041 | bugfdw2 | 10
GPORCA (wrong):
Gather Motion 3:1 (slice1; segments: 3)
-> Foreign Scan on fs1
Optimizer: GPORCA
gp_foreign_server | b | count
-------------------+---------+-------
0 | bugfdw1 | 20
0 | bugfdw2 | 10
The results are identical on REL_2_STABLE and main. With 3 segments and 2 foreign servers,
segment 2 wraps around to the first server, so bugfdw1 is read twice.
Operating System
Rocky Linux 9.7 (apache/incubator-cloudberry:cbdb-build-rocky9-latest), built with devops/build/automation/cloudberry/scripts.
Anything else
Joins on gp_foreign_server (a.gp_foreign_server = b.gp_foreign_server), which the feature
documents for co-located joins, also return wrong results under GPORCA because the column is
always 0. Workaround: SET optimizer = off before querying such tables.
Bug found by Claude Code. Please review it again.
- Ngôn ngữ chính
- C
- Star
- 1.4k
- Fork
- 273
- Merge trung bình
- 4 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 105
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/cloudberry
-
isolation2 lockmodes fails on cassert builds: extra AccessShareLock on partition rootCó thể đã có người làm @tuhaihe đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/cloudberry#2356 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
psql tab completion broken for storage servers, tags, profiles and resource groups (pre-PG15 query format)Có thể đã có người làm @allenvox đã nhận 5 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/cloudberry#2316 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] Expand fails to recognize user-defined tablespacesCó thể đã có người làm @nix-oss đã nhận 92 ngày trước. Đang mởtype: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/cloudberry#1885 · 2 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Có thể đã có người làm @talmacschen-arch đã nhận 153 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
apache/cloudberry#1825 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
type: Bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 53/100
apache/cloudberry#2350 · 1 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của apache/cloudberry
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
windows-artifacts: the win-arm64 job uses a Visual Studio generator missing from windows-11-armĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
wasm-micro-runtime/wasm-micro-runtime#5217 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
HandBrake/HandBrake#8278 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày