Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
575 B
2
Indexable
Never
DROP INDEX IF EXISTS idx_menu_unique;
CREATE UNIQUE INDEX IF NOT EXISTS idx_menu_unique
                                  ON menu USING BTREE(pizzeria_id, pizza_name);

SET enable_seqscan = OFF;

EXPLAIN ANALYZE
SELECT pizza_name,
       pizzeria_id
  FROM menu
 WHERE pizza_name > 'ch'
       AND pizzeria_id = 5;

EXPLAIN ANALYZE
SELECT m.pizza_name AS pizza_name,
       max(rating) OVER (PARTITION BY rating ORDER BY rating ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS k
  FROM menu m
       INNER JOIN pizzeria pz ON m.pizzeria_id = pz.id
 ORDER BY 1, 2;