Hello,
j'ai un petit probleme, j'ai une base de teste qui contient cette table :
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- Table: fakedata
 
-- DROP TABLE fakedata;
 
CREATE TABLE fakedata
(
  id serial NOT NULL,
  username character varying(128) NOT NULL,
  firstname character varying(128) NOT NULL,
  lastname character varying(128) NOT NULL,
  state character varying(128),
  city character varying(128),
  address character varying(128),
  zipcode character varying(128),
  homephone character varying(128),
  workphone character varying(128),
  email character varying(128) NOT NULL,
  bio text,
  regdate timestamp with time zone,
  CONSTRAINT fakedata_primary_id PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE fakedata OWNER TO postgres;
 
-- Index: fulltext_bio
 
-- DROP INDEX fulltext_bio;
 
CREATE INDEX fulltext_bio
  ON fakedata
  USING gin
  (to_tsvector('english'::regconfig, bio));
 
-- Index: index_email
 
-- DROP INDEX index_email;
 
CREATE INDEX index_email
  ON fakedata
  USING btree
  (email);
ALTER TABLE fakedata CLUSTER ON index_email;
 
-- Index: index_location
 
-- DROP INDEX index_location;
 
CREATE INDEX index_location
  ON fakedata
  USING btree
  (state, city, address, zipcode);
 
-- Index: index_name
 
-- DROP INDEX index_name;
 
CREATE INDEX index_name
  ON fakedata
  USING btree
  (firstname, lastname);
 
-- Index: index_username
 
-- DROP INDEX index_username;
 
CREATE INDEX index_username
  ON fakedata
  USING btree
  (username);
Elle contient 100.000 lignes, Seulement quand je fais une recherche fulltext, c'est très lent..
Par exemple cette requete prend a peut pret 20 secondes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
SELECT * FROM fakedata WHERE plainto_tsquery('Nostrum') @@ to_tsvector('english',bio);
Voila l'explain pour cette requête
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
Bitmap Heap Scan on fakedata  (cost=132.38..1789.39 rows=500 width=838)
  Recheck Cond: (plainto_tsquery('Nostrum'::text) @@ to_tsvector('english'::regconfig, bio))
  ->  Bitmap Index Scan on fulltext_bio  (cost=0.00..132.26 rows=500 width=0)
        Index Cond: (plainto_tsquery('Nostrum'::text) @@ to_tsvector('english'::regconfig, bio))
Savez vous comment je peux optimiser ça ?
Merci