Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exceptions caused by partitioned tables #412

Merged
merged 4 commits into from
Nov 11, 2024
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
25 changes: 25 additions & 0 deletions src/pgduckdb_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ IsCatalogTable(List *tables) {
return false;
}

static bool
ContainsPartitionedTable(List *rtes) {
foreach_node(RangeTblEntry, rte, rtes) {
if (rte->rtekind == RTE_SUBQUERY) {
/* Check whether any table in the subquery is a partitioned table */
if (ContainsPartitionedTable(rte->subquery->rtable)) {
return true;
}
}

if (rte->relkind == RELKIND_PARTITIONED_TABLE) {
return true;
}
}
return false;
}

static bool
IsDuckdbTable(Oid relid) {
if (relid == InvalidOid) {
Expand Down Expand Up @@ -147,6 +164,14 @@ IsAllowedStatement(Query *query, bool throw_error = false) {
return false;
}

/*
* When accessing the partitioned table, we temporarily let PG handle it instead of DuckDB.
*/
if (ContainsPartitionedTable(query->rtable)) {
elog(elevel, "DuckDB does not support querying PG partitioned table");
return false;
}

/*
* We don't support multi-statement transactions yet, so don't try to
* execute queries in them even if duckdb.force_execution is enabled.
Expand Down
9 changes: 9 additions & 0 deletions test/regression/expected/basic.out
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ SELECT COUNT(b) FROM t WHERE a > 3;
(1 row)

DROP TABLE t;
CREATE TABLE t (a INT) PARTITION BY LIST (a);
CREATE TABLE s (b INT);
SELECT * FROM t JOIN s ON a = b;
a | b
---+---
(0 rows)

DROP TABLE t;
DROP TABLE s;
6 changes: 6 additions & 0 deletions test/regression/sql/basic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ INSERT INTO t SELECT g % 100, MD5(g::VARCHAR) FROM generate_series(1,1000) g;
INSERT INTO t SELECT g % 100, MD5(g::VARCHAR) FROM generate_series(1,1000) g;
SELECT COUNT(b) FROM t WHERE a > 3;
DROP TABLE t;

CREATE TABLE t (a INT) PARTITION BY LIST (a);
CREATE TABLE s (b INT);
SELECT * FROM t JOIN s ON a = b;
DROP TABLE t;
DROP TABLE s;