Skip to content

Reject zero-column table creation with AO column storage #1163

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yjhjstz
Copy link
Member

@yjhjstz yjhjstz commented Jun 16, 2025

Creating a table with AO columnar storage and no columns is not supported. This patch adds an explicit check in DefineRelation() to throw an error when such a case is encountered. This ensures users receive a clear error message rather than encountering undefined behavior.

Also adds a regression test under misc_jiras to verify the behavior.

Fixes #1055

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


@gfphoenix78
Copy link
Contributor

I have two concerns about the issue:

  1. What's the behavior if we drop the aocs table to zero column?
  2. Is it possible to convert other type of table with zero column to aocs table?

@avamingli
Copy link
Contributor

What's the behavior if we drop the aocs table to zero column?
Is it possible to convert other type of table with zero column to aocs table?

@gfphoenix78 can you provide sql ?

create a table with one column, then drop the column.

Same concern, create a table with zero column is valid in Postgres/GPDB.

@avamingli
Copy link
Contributor

What's the behavior if we drop the aocs table to zero column?
Is it possible to convert other type of table with zero column to aocs table?

@gfphoenix78 can you provide sql ?

create a table with one column, then drop the column.

Same concern, create a table with zero column is valid in Postgres/GPDB.

What's the behavior if we drop the aocs table to zero column?
Is it possible to convert other type of table with zero column to aocs table?

@gfphoenix78 can you provide sql ?

create a table with one column, then drop the column.

Same concern, create a table with zero column is valid in Postgres/GPDB.

Designed to be valid.
https://www.postgresql.org/docs/14/sql-createtable.html

Zero-Column Tables
PostgreSQL allows a table of no columns to be created (for example, CREATE TABLE foo();). This is an extension from the SQL standard, which does not allow zero-column tables. Zero-column tables are not in themselves very useful, but disallowing them creates odd special cases for ALTER TABLE DROP COLUMN, so it seems cleaner to ignore this spec restriction.

@yjhjstz
Copy link
Member Author

yjhjstz commented Jun 17, 2025

Is it possible to convert other type of table with zero column to aocs table?

fec6f10 try to reject , if agreed, then I will add related testcase.

@gfphoenix78
Copy link
Contributor

What's the behavior if we drop the aocs table to zero column?
Is it possible to convert other type of table with zero column to aocs table?

@gfphoenix78 can you provide sql ?

create a table with one column, then drop the column.

Same concern, create a table with zero column is valid in Postgres/GPDB.

Yes. The normal table with columns may drop columns one by one, until to have no column.

This PR only disallow aocs table to create a zero-column table, but we may still have zero-column table in other table storage. ALTER TABLE ... SET ACCESS METHOD may convert other table storage to aocs, which is also invalid.


-- Github Issue 1055
-- AO column storage not supported for zero-column tables
set default_table_access_method = ao_column;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add more test cases here:

  1. alter table ... drop column ... to drop columns one by one until to zero-column.
  2. alter table ... set access method from other type of table storage to aocs.

Copy link
Member Author

Choose a reason for hiding this comment

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

drop columns one by one until to zero-column

wild to reject drop column to zero ?

@yjhjstz yjhjstz force-pushed the fix_issue_1105 branch 2 times, most recently from d4d3540 to 59af48e Compare June 26, 2025 16:12
Creating a table with AO columnar storage and no columns is not supported.
This patch adds an explicit check in DefineRelation() to throw an error
when such a case is encountered. This ensures users receive a clear error
message rather than encountering undefined behavior.

Also adds a regression test under misc_jiras to verify the behavior.

Reported-by: GitHub Issue apache#1055
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] AO column table can't process zero-column table
4 participants