optimization - How to optimize my PostgreSQL DB for prefix search? -


I have a table called "nodes" with approximately 1.7 million lines in PostgreSQL db

 < Code> = # \ D nodes table "public.nodes" column | | Type | Modifier -------- + ------------------------ + ----------- ID Integer | Faucet title | Character different (256) Score | Double precision | Index: "nodes_pkey" primary key, btree (id)  

I want to use information from that table to auto-complete a search field, in which the user has the top ten titles The list shows the fitting score for my input so I used this query (Looking for all the titles starting with "S" here)

  = # Analysis title Analyze, where the score from the node is Aiaieli the% 'order by Rshk; Question Scheme ------------------------------------------------ -------------------------------------------------- --------------------- Sort (cost = 64177.92..64581.38 rows = width of 161385 = 25) (real time = 4930.334..5047.321 rows = 161264 loops = 1) Sort key: Score sort method: External merge disk: 5712kB - & gt; Sequence scan on nodes (cost = 0.00.4.46630.50 rows = width of 161385 = 25) (real time = 0.611..4464.413 rows = 161264 loop = 1) Filter: ((title) :: text ~~ * '%%' :: Text) Total runtime: 5260.791 ms (6 lines)  

With this information it was slow to use with automatic completion, Was able to improve

  = # on index nodes using index title _idx btree (short (title) text_pattern_ops); = Select Lecture Analysis of the title, score from the nodes, where the score score range is less than the low (title) low score ('%'); Question Scheme ------------------------------------------------ -------------------------------------------------- ---------------------------------------- boundary (cost = 18122.41..18122.43 rows = 10's width = 25) (real time = 1324.703..1324.708 rows = 10 loops = 1) - & gt; Sort (cost = 18122.41..18144.60 rows = 8876 width = 25) (real time = 1324.700..1324.702 lines = 10 loops = 1) Sort key: Score sort method: Top-N HOPPER Memory: 17 KB - & gt; ; Heap scan on bitmap nodes (cost = 243.53..17930.60 rows = 8876 width = 25) (real time = 96.124..1227.203 rows = 161264 loop = 1) Filter: (bottom (title) :: text) ~~ 's % ':: text) - & gt; Bitmap index scan title_ idx (cost = 0.00..241.31 rows = 8876 width = 0) (real time = 90.059..90.059 rows = 161264 loop = 1) index curve: ((less (title) :: text) ~> ; ~ = 'S' :: text) and (less (title) :: text) ~ ~ ~ ~ t ':: text) Total runtime: 1325.085 ms (9 lines)  

So it has given me the speed of factor 4. But can this be further improved? If I select '% s' instead of '% s%' What would happen if i want to use? Is there any chance of performing well with SQL? Or should I try a different solution (Lucin, Sphinx?) To implement my own full feature?

< Div class = "post-text" itemprop = "text">

If you are not in the C locale, then you will need a text_pattern_ops index.

View:.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -