Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Indexes are not replaced after upgrading a materialised view #334

Open
mattgibson opened this issue Aug 24, 2021 · 1 comment · May be fixed by #364
Open

Indexes are not replaced after upgrading a materialised view #334

mattgibson opened this issue Aug 24, 2021 · 1 comment · May be fixed by #364
Milestone

Comments

@mattgibson
Copy link

Two quirks of our setup might explain this

  1. the indexes have custom names
  2. We are using a custom schema name rather than public

Not had time to find out which yet.

@Jamedjo
Copy link

Jamedjo commented Aug 25, 2021

Filtering on t.relname doesn't work because the namespace is prefixed in the call to update_view:

pry> Scenic::Adapters::Postgres::Indexes.new(connection: ActiveRecord::Base.connection).on('shop.products')
   (1.9ms)              SELECT
              t.relname as object_name,
              i.relname as index_name,
              pg_get_indexdef(d.indexrelid) AS definition
            FROM pg_class t
            INNER JOIN pg_index d ON t.oid = d.indrelid
            INNER JOIN pg_class i ON d.indexrelid = i.oid
            LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
            WHERE i.relkind = 'i'
              AND d.indisprimary = 'f'
              AND t.relname = 'shop.products'
              AND n.nspname = ANY (current_schemas(false))
            ORDER BY i.relname
=> []

If we were to filter just on the actual name we would find the index:

pry> Scenic::Adapters::Postgres::Indexes.new(connection: ActiveRecord::Base.connection).on('products')
   (5.8ms)              SELECT
              t.relname as object_name,
              i.relname as index_name,
              pg_get_indexdef(d.indexrelid) AS definition
            FROM pg_class t
            INNER JOIN pg_index d ON t.oid = d.indrelid
            INNER JOIN pg_class i ON d.indexrelid = i.oid
            LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
            WHERE i.relkind = 'i'
              AND d.indisprimary = 'f'
              AND t.relname = 'products'
              AND n.nspname = ANY (current_schemas(false))
            ORDER BY i.relname

=> [#<Scenic::Index:0x0000557cea1d5418
  @definition="CREATE UNIQUE INDEX products_unique_sku_dates ON shop.products USING btree (\"Day\", \"Component\", \"SKU\")",
  @index_name="products_unique_sku_dates",
  @object_name="products">]

Should this query be updated split "shop.products", filter on t.relname = 'products' and to also filter on relnamespace?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants