Fail with a clear error when scanning a partitioned table#435
Open
simi wants to merge 1 commit intoduckdb:mainfrom
Open
Fail with a clear error when scanning a partitioned table#435simi wants to merge 1 commit intoduckdb:mainfrom
simi wants to merge 1 commit intoduckdb:mainfrom
Conversation
Scanning a partitioned table caused an infinite hang because PostgreSQL sets relpages=-1 for relkind='p' tables. Cast to idx_t (uint64) gives pages_approx = 2^64-1, so the scanner loops over ~18 quintillion pages. Now throws NotImplementedException at bind time with a message that includes the relation kind and table name.
simi
commented
Apr 11, 2026
| return result; | ||
| } | ||
|
|
||
| string PostgresUtils::RelkindToString(const string &relkind) { |
Author
There was a problem hiding this comment.
Even patch is targeted to partitioned tables, same issue would be now for any relkind. This mapping in here is to provide nice error message only for user with safe fallback. It handles all relkinds loaded at
simi
commented
Apr 11, 2026
| info->approx_num_pages = approx_num_pages; | ||
| auto relpages = result.IsNull(row, 2) ? 0 : result.GetInt64(row, 2); | ||
| auto relkind = result.IsNull(row, 12) ? string() : result.GetString(row, 12); | ||
| info->approx_num_pages = GetScanRelpages(relpages, relkind, table_name); |
Author
There was a problem hiding this comment.
GetScanRelpages is planned to be kept even once partitioned tables are fully supported as a guard for unexpected raw values.
simi
commented
Apr 11, 2026
| for (idx_t row = 0; row < rows; row++) { | ||
| AddColumnOrConstraint(&transaction, &schema, *result, row, *table_info); | ||
| } | ||
| table_info->approx_num_pages = result->GetInt64(0, 2); |
Author
There was a problem hiding this comment.
This and following GetInt64 missed the null check. Was it intended? I have added it in my change.
Author
|
I'll check on CI failures. |
Collaborator
|
Just FYI, some details on local test runs: #431 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scanning a partitioned table caused an infinite hang because PostgreSQL sets relpages=-1 for relkind='p' tables. Cast to idx_t (uint64) gives pages_approx = 2^64-1, so the scanner loops over ~18 quintillion pages.
Now throws NotImplementedException at bind time with a message that includes the relation kind and table name.
Initial step to provide support (yes, by gracefully fail for now, better than hang IMHO) for partitioned tables, since those are broken as reported at #220.
I have plan to open set of smaller PRs to improve the situation ending with full support of partitioned tables. This is initial foundation - accepting the broken state, add friendly error and add testing infrastructure.
Example EXPLAIN (SELECT hangs):
pg_classreturns