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

Convert CREATE INDEX SQL into pgroll operation #551

Merged
merged 1 commit into from
Jan 2, 2025
Merged

Conversation

ryanslade
Copy link
Collaborator

@ryanslade ryanslade commented Dec 19, 2024

Convert the majority of CREATE INDEX statements into OpCreateIndex

The following cases are covered:

CREATE INDEX idx_name ON foo (bar)
CREATE INDEX idx_name ON foo (bar ASC)
CREATE INDEX idx_name ON foo USING btree (bar)
CREATE INDEX idx_name ON foo USING brin (bar)
CREATE INDEX idx_name ON foo USING gin (bar)
CREATE INDEX idx_name ON foo USING gist (bar)
CREATE INDEX idx_name ON foo USING hash (bar)
CREATE INDEX idx_name ON foo USING spgist (bar)
CREATE INDEX CONCURRENTLY idx_name ON foo (bar)
CREATE INDEX idx_name ON schema.foo (bar)
CREATE INDEX idx_name ON foo (bar, baz)
CREATE UNIQUE INDEX idx_name ON foo (bar)
CREATE INDEX idx_name ON foo (bar) WHERE (foo > 0)
CREATE INDEX idx_name ON foo (bar) WHERE foo > 0
CREATE INDEX idx_name ON foo (bar) WITH (fillfactor = 70)
CREATE INDEX idx_name ON foo (bar) WITH (deduplicate_items = true)
CREATE INDEX idx_name ON foo (bar) WITH (buffering = ON)
CREATE INDEX idx_name ON foo (bar) WITH (buffering = OFF)
CREATE INDEX idx_name ON foo (bar) WITH (buffering = AUTO)
CREATE INDEX idx_name ON foo (bar) WITH (fastupdate = true)
CREATE INDEX idx_name ON foo (bar) WITH (pages_per_range = 100)
CREATE INDEX idx_name ON foo (bar) WITH (autosummarize = true)
CREATE INDEX idx_name ON foo (bar) WITH (fillfactor = 70, deduplicate_items = true)

And the following unsupported cases fall back to RAW SQL:

CREATE INDEX idx_name ON foo (bar) TABLESPACE baz
CREATE INDEX idx_name ON foo (bar COLLATE en_US)
CREATE INDEX idx_name ON foo (bar DESC)
CREATE INDEX idx_name ON foo (bar NULLS FIRST)
CREATE INDEX idx_name ON foo (bar NULLS LAST)
CREATE INDEX idx_name ON foo (bar) INCLUDE (baz)
CREATE INDEX idx_name ON foo (bar opclass (test = test))
CREATE INDEX idx_name ON foo (bar opclass)
CREATE INDEX idx_name ON ONLY foo (bar)
CREATE INDEX idx_name ON foo(a) NULLS NOT DISTINCT
CREATE INDEX IF NOT EXISTS idx_name ON foo(a)
CREATE INDEX idx_name ON foo(LOWER(a))
CREATE INDEX idx_name ON foo(a, LOWER(b))

@ryanslade ryanslade marked this pull request as ready for review December 19, 2024 14:14
@andrew-farries andrew-farries self-assigned this Dec 20, 2024
@andrew-farries andrew-farries force-pushed the rs/create-index branch 4 times, most recently from 5469ddc to d912b21 Compare December 23, 2024 08:48
@andrew-farries andrew-farries changed the base branch from main to update-pg-query-go-dependency December 23, 2024 08:48
@andrew-farries
Copy link
Collaborator

andrew-farries commented Dec 23, 2024

I think this is good to go now @ryanslade. Changes I made:

  • Use raw SQL for indexes created with ONLY
  • Use raw SQL for NULLS NOT DISTINCT indexes
  • Use raw SQL for IF NOT EXISTS index creation
  • Use raw SQL for indexes on expressions
  • I made a change to our fork of pg_query_go (Add support for deparsing AST reloptions nodes pg_query_go#6) to allow deparsing of storage_options clauses. This allows us to remove the manual deparsing of those nodes from this PR.
  • Removed the restriction on having > 1 storage parameter
  • Added comments
  • Updated the PR description

I also made #565 to simplify the use of the OpCreateIndex struct and remove the needless pointer fields.

This PR is now stacked on:

@ryanslade
Copy link
Collaborator Author

Nice! The two PRs lower in the stack look good so we can merge those into main and then prepare this for merge too 👍

@andrew-farries andrew-farries force-pushed the update-pg-query-go-dependency branch from 65b7013 to eed8227 Compare January 2, 2025 11:03
Base automatically changed from update-pg-query-go-dependency to main January 2, 2025 11:09
Convert `CREATE INDEX` statements to `OpCreateIndex` operations.

Supported SQL statements:

```sql
CREATE INDEX idx_name ON foo (bar)
CREATE INDEX idx_name ON foo (bar ASC)
CREATE INDEX idx_name ON foo USING btree (bar)
CREATE INDEX idx_name ON foo USING brin (bar)
CREATE INDEX idx_name ON foo USING gin (bar)
CREATE INDEX idx_name ON foo USING gist (bar)
CREATE INDEX idx_name ON foo USING hash (bar)
CREATE INDEX idx_name ON foo USING spgist (bar)
CREATE INDEX CONCURRENTLY idx_name ON foo (bar)
CREATE INDEX idx_name ON schema.foo (bar)
CREATE INDEX idx_name ON foo (bar, baz)
CREATE UNIQUE INDEX idx_name ON foo (bar)
CREATE INDEX idx_name ON foo (bar) WHERE (foo > 0)
CREATE INDEX idx_name ON foo (bar) WHERE foo > 0
CREATE INDEX idx_name ON foo (bar) WITH (fillfactor = 70)
CREATE INDEX idx_name ON foo (bar) WITH (deduplicate_items = true)
CREATE INDEX idx_name ON foo (bar) WITH (buffering = ON)
CREATE INDEX idx_name ON foo (bar) WITH (buffering = OFF)
CREATE INDEX idx_name ON foo (bar) WITH (buffering = AUTO)
CREATE INDEX idx_name ON foo (bar) WITH (fastupdate = true)
CREATE INDEX idx_name ON foo (bar) WITH (pages_per_range = 100)
CREATE INDEX idx_name ON foo (bar) WITH (autosummarize = true)
CREATE INDEX idx_name ON foo (bar) WITH (fillfactor = 70, deduplicate_items = true)
```
@ryanslade ryanslade merged commit e6e4523 into main Jan 2, 2025
28 checks passed
@ryanslade ryanslade deleted the rs/create-index branch January 2, 2025 11:16
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