Skip to content

Allow the creation of a partial index #716

Open

Description

@lukehutch

Is your feature request related to a problem? Please describe.

I need to be able to index sparse boolean columns. The most efficient way to do that in Postgres is to create a partial index, e.g.

CREATE INDEX ON mytable((1)) WHERE boolcolumn;

I don't see a way to express that in the current Serverpod yaml syntax. Can this be added, please?

Activity

  1. added
    enhancement
    on Mar 8, 2023
  2. vlidholt commented on Mar 8, 2023

    @vlidholt
    Collaborator

    This should be added in the future. In the mean time, it's possible to manually add the index to your database using SQL.

  3. lukehutch commented on Apr 24, 2024

    @lukehutch
    ContributorAuthor

    Also I'm not sure if WHERE boolcolumn is going to be interpreted the same way as WHERE boolcolumn = TRUE, in terms of whether the partial index is used or not, but the latter syntax would be better for Serverpod partial indexes, because the Serverpod query syntax requires testing where: (t) => boolcolumn.equals(true).

    Then the yaml syntax for the index would require the user to specify something like

    indexes:
      tablename_boolcolumn_idx:
        fields: boolcolumn
        whereValueEquals: true

    (maybe a more comprehensive syntax could be provided to allow for inequalities etc., but simple equals / notEquals checks would satisfy my own needs for partial indices, at least)

  4. lukehutch commented on Jul 11, 2024

    @lukehutch
    ContributorAuthor
  5. added
    area: database
    on Dec 17, 2024
  6. t-kietzmann commented on Jun 12, 2026

    @t-kietzmann

    Wanna push this again. Would be a great benefit, especially when working with soft-deletes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: databaseenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions