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

It may be useful to implement universal method for creating all possible standard indexes for any table #8

Open
Konard opened this issue Oct 19, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Konard
Copy link
Member

Konard commented Oct 19, 2021

https://github.com/deepcase/materialized-path/blob/011c8b6b7464097357d2435b6822aa4003887837/migrations/1633562151439-multidirectional.ts#L158-L182

PostgreSQL limits the number of columns for each index with 32 columns.
Indexes can be created for all possible combination of 1, 2, ... N columns. Where N is not greater than 32, but is configurable by user.
It is well-defined for each of PostgreSQL type which indexes are better suited for that type.
So this stored procedure should have two optional arguments - the maximum number of columns for combined indexes and the restricted set of applied index types (B-tree, hash, etc.).

Once this stored procedure is done, the next step will be to implement a stored procedure that will delete all unused indexes. Used indexes can be checked using stats.

On the second thought, I think it should be a good idea to have a mandatory limitation on the maximum number of columns for combined indexes. If we do not limit it and use 32, we will end up with this number of possible combinations:

Sum[CatalanNumber[i], {i, 1, 32}] = 75 254 198 337 177 847

https://www.wolframalpha.com/input/?i=Sum%5BCatalanNumber%5Bi%5D%2C+%7Bi%2C+1%2C+32%7D%5D

We can use smaller numbers:

Sum[CatalanNumber[i], {i, 1, 16}] = 48760366
Sum[CatalanNumber[i], {i, 1, 8}] = 2055
Sum[CatalanNumber[i], {i, 1, 4}] = 22
Sum[CatalanNumber[i], {i, 1, 2}] = 3
@Konard Konard added the enhancement New feature or request label Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant