From 04f4f906b0d65bd8f2331b784f8ec1b2dd9e30f3 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 14 Nov 2020 16:41:07 +0100 Subject: [PATCH] Restore performance indexes from #927 --- migrations/0106.sql | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/migrations/0106.sql b/migrations/0106.sql index f7eab4dd..f2a8b334 100644 --- a/migrations/0106.sql +++ b/migrations/0106.sql @@ -1,3 +1,33 @@ +CREATE INDEX ix_products_performance1 ON products ( + parent_product_id +); + +CREATE INDEX ix_products_performance2 ON products ( + CASE WHEN parent_product_id IS NULL THEN id ELSE parent_product_id END, + active +); + +CREATE INDEX ix_stock_performance1 ON stock ( + product_id, + open, + best_before_date, + amount +); + +DROP VIEW products_resolved; +CREATE VIEW products_resolved +AS +SELECT + CASE + WHEN p.parent_product_id IS NULL THEN + p.id + ELSE + p.parent_product_id + END AS parent_product_id, + p.id as sub_product_id +FROM products p +WHERE p.active = 1; + DROP VIEW stock_missing_products_including_opened; CREATE VIEW stock_missing_products_including_opened AS