Skip to content

all_cons_columns#1277

Open
zuinuan123 wants to merge 1 commit intoIvorySQL:masterfrom
zuinuan123:master
Open

all_cons_columns#1277
zuinuan123 wants to merge 1 commit intoIvorySQL:masterfrom
zuinuan123:master

Conversation

@zuinuan123
Copy link
Copy Markdown

@zuinuan123 zuinuan123 commented Mar 27, 2026

view all_cons_columns make it

Summary by CodeRabbit

  • New Features
    • Added all_cons_columns view that exposes constraint-to-column mappings across database objects. This view provides comprehensive visibility into constraint relationships, including constraint names, associated columns, position information, and normalized data types, while respecting schema and table access permissions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

A new SQL view all_cons_columns was added to expose database constraint-to-column mappings by joining PostgreSQL system tables (pg_constraint, pg_class, pg_namespace, pg_attribute, pg_type) with filters for constraint types, schema privileges, and relation kinds.

Changes

Cohort / File(s) Summary
New Constraint Metadata View
contrib/ivorysql_ora/src/sysview/sysview_procedures.sql
Added all_cons_columns view that maps constraints to their constituent columns, normalizing data types via CASE statement mapping (e.g., varchar→VARCHAR2, numeric/int*→NUMBER, text→CLOB) and filtering for constraint types p, u, f, c with privilege validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hopping through constraints with bunny-eared glee,
A new view arrives for all to see,
Columns and constraints in perfect array,
The all_cons_columns view saves the day! 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'all_cons_columns' is the name of the view being added but lacks descriptive context about what the change accomplishes. Revise title to describe the action and purpose, e.g., 'Add all_cons_columns view for constraint-to-column mappings' or 'Implement all_cons_columns system view'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@contrib/ivorysql_ora/src/sysview/sysview_procedures.sql`:
- Line 278: The view all_cons_columns is not schema-qualified and lacks an
explicit GRANT; change the CREATE OR REPLACE VIEW invocation to create
SYS.all_cons_columns (i.e., qualify the view with the SYS schema) and add an
explicit grant statement (GRANT SELECT ON SYS.all_cons_columns TO PUBLIC)
alongside the other SYS compatibility grants near the existing grant block so
the view is created in SYS and accessible to PUBLIC; update any nearby
references in this file to the qualified name if needed.
- Line 311: The relkind filter in the sysview that builds constraint listings
currently omits partitioned tables by using cls.relkind IN ('r','v','m'); update
that filter to include partitioned tables (add 'p') so constraints on
partitioned tables are returned—modify the clause that references cls.relkind in
sysview_procedures.sql accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 83c01960-c4fa-4cfb-b2c4-5325d492595d

📥 Commits

Reviewing files that changed from the base of the PR and between 479acbd and 21385f5.

📒 Files selected for processing (1)
  • contrib/ivorysql_ora/src/sysview/sysview_procedures.sql

OBJECT_ID
;

CREATE OR REPLACE VIEW all_cons_columns AS
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Create the view in SYS and grant it explicitly.

At Line 278, all_cons_columns is not schema-qualified, and there is no GRANT for this new view near Line 319–Line 320. In this file, SYS compatibility views are created as SYS.<view> and granted to PUBLIC; this one currently breaks that pattern and can end up inaccessible or in the wrong schema.

🔧 Proposed fix
-CREATE OR REPLACE VIEW all_cons_columns AS
+CREATE OR REPLACE VIEW SYS.ALL_CONS_COLUMNS AS
 ...
 ORDER BY
     owner, table_name, constraint_name, position;
 
 /* GRANT SELECT PRIVILEGE TO PUBLIC */
 GRANT SELECT ON SYS.USER_PROCEDURES TO PUBLIC;
+GRANT SELECT ON SYS.ALL_CONS_COLUMNS TO PUBLIC;

Also applies to: 319-320

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contrib/ivorysql_ora/src/sysview/sysview_procedures.sql` at line 278, The
view all_cons_columns is not schema-qualified and lacks an explicit GRANT;
change the CREATE OR REPLACE VIEW invocation to create SYS.all_cons_columns
(i.e., qualify the view with the SYS schema) and add an explicit grant statement
(GRANT SELECT ON SYS.all_cons_columns TO PUBLIC) alongside the other SYS
compatibility grants near the existing grant block so the view is created in SYS
and accessible to PUBLIC; update any nearby references in this file to the
qualified name if needed.

WHERE
con.contype IN ('p', 'u', 'f', 'c')
AND nsp.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
AND cls.relkind IN ('r', 'v', 'm')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In PostgreSQL system catalog pg_class, what relkind value represents partitioned tables, and can table constraints (primary key/unique/check/foreign key) exist on relkind 'p' relations?

💡 Result:

In PostgreSQL system catalog pg_class, the relkind value 'p' represents partitioned tables. Table constraints can exist on relkind 'p' relations (partitioned tables): - CHECK constraints: Yes, but they are inherited by all partitions; NO INHERIT CHECK constraints are not allowed on partitioned tables. - Primary key and unique constraints: Yes, but with limitations—the constraint must include all partition key columns (no expressions or function calls in partition key for these), as uniqueness is enforced per-partition relying on partitioning to prevent cross-partition duplicates. - Foreign key constraints: Can be declared on partitioned tables (referencing them or referenced by them), but with practical limitations—FKs referencing partitioned tables check all partitions, which can be slow for detach/drop operations; recommended to define FKs between matching partitions instead.

Citations:


🏁 Script executed:

cd contrib/ivorysql_ora/src/sysview && head -n 320 sysview_procedures.sql | tail -n 20

Repository: IvorySQL/IvorySQL

Length of output: 953


🏁 Script executed:

cd contrib/ivorysql_ora/src/sysview && sed -n '300,320p' sysview_procedures.sql

Repository: IvorySQL/IvorySQL

Length of output: 958


🏁 Script executed:

cd contrib/ivorysql_ora/src/sysview && sed -n '280,315p' sysview_procedures.sql

Repository: IvorySQL/IvorySQL

Length of output: 1777


🏁 Script executed:

cd contrib/ivorysql_ora/src/sysview && sed -n '260,285p' sysview_procedures.sql

Repository: IvorySQL/IvorySQL

Length of output: 833


Include partitioned tables in relkind filter.

Line 311 excludes relkind = 'p', so constraints defined on partitioned tables will be missing from this view. PostgreSQL partitioned tables can have primary key, unique, foreign key, and check constraints, all of which are supported by this query's constraint type filter.

Current code
    AND cls.relkind IN ('r', 'v', 'm')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contrib/ivorysql_ora/src/sysview/sysview_procedures.sql` at line 311, The
relkind filter in the sysview that builds constraint listings currently omits
partitioned tables by using cls.relkind IN ('r','v','m'); update that filter to
include partitioned tables (add 'p') so constraints on partitioned tables are
returned—modify the clause that references cls.relkind in sysview_procedures.sql
accordingly.

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.

1 participant