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

Conversation

Leo-XM-Zeng
Copy link
Contributor

Because we do not yet have good support for partitioned tables, the following code triggers assertions. #409

/*
 * RelationGetNumberOfBlocksInFork
 *		Determines the current number of pages in the specified relation fork.
 *
 * Note that the accuracy of the result will depend on the details of the
 * relation's storage. For builtin AMs it'll be accurate, but for external AMs
 * it might not be.
 */
BlockNumber
RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)
{
	if (RELKIND_HAS_TABLE_AM(relation->rd_rel->relkind))
	{
		/*
		 * Not every table AM uses BLCKSZ wide fixed size blocks. Therefore
		 * tableam returns the size in bytes - but for the purpose of this
		 * routine, we want the number of blocks. Therefore divide, rounding
		 * up.
		 */
		uint64		szbytes;

		szbytes = table_relation_size(relation, forkNum);

		return (szbytes + (BLCKSZ - 1)) / BLCKSZ;
	}
	else if (RELKIND_HAS_STORAGE(relation->rd_rel->relkind))
	{
		return smgrnblocks(RelationGetSmgr(relation), forkNum);
	}
	else
		Assert(false);

	return 0;					/* keep compiler quiet */
}

What does this PR do?

When accessing the partition table, we temporarily let PG handle it instead of DuckDB.
This temporarily avoids the unavailability of the system due to an assertion.

…nstead of DuckDB.

This temporarily avoids the unavailability of the system due to an assertion.
Copy link
Collaborator

@JelteF JelteF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix. Some small naming suggestions, but other than that this looks good.

@@ -52,6 +52,23 @@ IsCatalogTable(List *tables) {
return false;
}

static bool
IsPartitionedTable(List *tables) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Is is the wrong prefix here and the argument name tables is also confusing. We pass it a list of tables RTEs not a single table. I realize the problem is the case for IsCatalogTable, but we should change this there too (not in this PR though).

Suggested change
IsPartitionedTable(List *tables) {
ContainsPartitionedTable(List *rtes) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the IsCatalogTable function information #417

IsPartitionedTable(List *tables) {
foreach_node(RangeTblEntry, table, tables) {
if (table->rtekind == RTE_SUBQUERY) {
/* Check whether the table in the subquery is a partitioned table */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Check whether the table in the subquery is a partitioned table */
/* Check whether any table in the subquery is a partitioned table */

@JelteF JelteF merged commit 1b4514d into duckdb:main Nov 11, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants