SeaQL / sea-query

🔱 A dynamic SQL query builder for MySQL, Postgres and SQLite
https://www.sea-ql.org
Other
1.12k stars 182 forks source link

Support for Postgres BTree index `INCLUDE (<col>, ...)` #775

Open theelderbeever opened 4 months ago

theelderbeever commented 4 months ago

Motivation

Postgres BTree indexex allow for an INCLUDE statement where the included columns values are stored in the leaf nodes of the index. This is an optimization to store data with the index for columns that are fetched commonly but, not necessarily filtered on.

Proposed Solutions

Index::create()
        .name(name)
        .index_type(IndexType::BTree)
        .table(table)
        .col(col)
        .include(other_cols) // postgres feature gate
        .is_unique_key();
CREATE UNIQUE INDEX an_index ON table USING BTREE (col) INCLUDE (other_cols)

Additional Information

I am unsure if this is supported on other databases.

CREATE INDEX