Hello,
j'ai un petit problème, j'ai une table avec une colonne tsvector et un index GIN dessus, seulement postgresql ne les utilise pas quand je vais ce genre de requêtes :
Savez vous pourquoi ? peut-on le forcer a utiliser l'index ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part select id,title from blog_article where tsv @@ plainto_tsquery('hello');
Voila la définition de la table :
Les indexes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 CREATE TABLE blog_article ( id serial NOT NULL, title character varying(255) NOT NULL, header_image character varying(255), slug character varying(50) NOT NULL, format integer NOT NULL, category_id integer NOT NULL, author_id integer NOT NULL, "content" text NOT NULL, comments_enabled boolean NOT NULL, publication_mode integer NOT NULL, date_of_creation timestamp with time zone NOT NULL, date_of_modification timestamp with time zone NOT NULL, tsv tsvector, CONSTRAINT blog_article_pkey PRIMARY KEY (id), CONSTRAINT blog_article_author_id_fkey FOREIGN KEY (author_id) REFERENCES auth_user (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED, CONSTRAINT category_id_refs_id_25820696 FOREIGN KEY (category_id) REFERENCES blog_category (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED, CONSTRAINT blog_article_slug_key UNIQUE (slug), CONSTRAINT blog_article_title_key UNIQUE (title) ) WITH (OIDS=FALSE);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 CREATE INDEX blog_article_author_id ON blog_article USING btree (author_id);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 CREATE INDEX blog_article_category_id ON blog_article USING btree (category_id);et le Trigger pour mettre a jour tsv
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 CREATE INDEX blog_article_tsv ON blog_article USING gin (tsv);
Que faire ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON blog_article FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('tsv', 'pg_catalog.french', 'title', 'content');
Merci
Partager