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

Support creating different index types #417

Merged
merged 17 commits into from
Oct 29, 2024
Merged

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Oct 18, 2024

This PR adds new options to create_index operation:

  • method: enum for setting different index types. Default: btree. Available options: btree, hash, gist, spgist, gin, brin.
  • storage_parameters: optional storage parameters for the index.

Example operation to create a new hash index with custom fillfactor:

{
  "name": "10_create_index",
  "operations": [
    {
      "create_index": {
        "name": "idx_fruits_name",
        "table": "fruits",
        "columns": [
          "name"
        ],
	"method": "hash",
	"storage_parameters": "fillfactor = 70"
      }
    }
  ]
}

Furthermore, analyze now return the index method under the name method and the definition under definition.
Please note that the definition pgroll returns is not the SQL statement pgroll runs when running create_index migrations.

{
 "idx_fruits_name": {
   "name": "idx_fruits_name",
   "unique": false,
   "columns": [
     "name"
   ],
   "method": "hash",
   "definition": "CREATE INDEX idx_fruits_name ON public.fruits USING hash (name) WITH (fillfactor='70')"
 }
}

Closes #378

@kvch kvch requested a review from andrew-farries October 18, 2024 13:22
Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

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

This looks good 👍

  • We should update the documentation with the new index options.
  • Consider adding an example migration that shows the new index options and link to it from the docs.

Comment on lines +230 to +235
},
"method": {
"description": "Index method to use for the index: btree, hash, gist, spgist, gin, brin",
"type": "string",
"enum": ["btree", "hash", "gist", "spgist", "gin", "brin"]
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could add some new json schema tests under pkg/jsonschema to test valid and invalid index types.

pkg/migrations/op_common_test.go Show resolved Hide resolved
@kvch kvch requested a review from andrew-farries October 28, 2024 15:45
@kvch kvch enabled auto-merge (squash) October 29, 2024 11:12
@kvch kvch merged commit e2f1740 into xataio:main Oct 29, 2024
25 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.

Allow creating different types of indexes and/or return more information about an index type
2 participants