Created
February 4, 2021 00:43
-
-
Save montanalow/a750780e7fcf69bee8dfa5db5b32d91d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Denormalize keywords onto items | |
CREATE FUNCTION denormalize_product_keywords_to_items() RETURNS trigger | |
LANGUAGE plpgsql | |
AS $$ | |
begin | |
select keywords into NEW.keywords from products where NEW.product_id = products.product_id; | |
return NEW; | |
end | |
$$; | |
-- Whenever an item is inserted or updated | |
CREATE TRIGGER items_search_index | |
BEFORE INSERT OR UPDATE ON items | |
FOR EACH ROW EXECUTE FUNCTION denormalize_product_keywords_to_items(); | |
-- You'll need to enable this extension to mix btree and gin indexes | |
CREATE EXTENSION IF NOT EXISTS btree_gin WITH SCHEMA public; | |
-- Create the compound index | |
CREATE INDEX items_search_index ON items USING gin(keywords, retail_location_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment