mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 13:26:14 +02:00
Speed-up stock_current by improving products_resolved and creating indices.
This commit is contained in:
parent
c3f54df1f8
commit
0872de5ff3
31
migrations/0106.sql
Normal file
31
migrations/0106.sql
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
DROP INDEX IF EXISTS _index_products_parents;
|
||||||
|
DROP INDEX IF EXISTS _index_stock_products_amount;
|
||||||
|
|
||||||
|
CREATE INDEX _index_products_parents ON products (parent_product_id);
|
||||||
|
CREATE INDEX _index_stock_products_amount ON stock (product_id, open, best_before_date, amount);
|
||||||
|
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS _index_product_parents_2;
|
||||||
|
CREATE INDEX _index_product_parents_2
|
||||||
|
ON products (
|
||||||
|
/* see products_resolved */
|
||||||
|
CASE WHEN parent_product_id IS NULL THEN id ELSE parent_product_id END,
|
||||||
|
active
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Old version is in 0103.sql
|
||||||
|
*/
|
||||||
|
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 active = 1;
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user