- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 195字
- 2021-07-09 19:57:22
Speed up LIKE queries
LIKE queries definitely cause some of the worst performance problems faced by people around the globe these days. In most database systems, LIKE is pretty slow and requires a sequential scan. In addition to that, end users quickly figure out that a fuzzy search will in many cases return better results than precise queries. A single type of LIKE query on a large table can, therefore, often cripple the performance of an entire database server if it is called often enough.
Fortunately, PostgreSQL offers a solution to the problem and the solution happens to be installed already:
test=# explain SELECT * FROM t_location WHERE name LIKE '%neusi%';
QUERY PLAN
-----------------------------------------------------------------
Bitmap Heap Scan on t_location
(cost=4.33..19.05 rows=24 width=13)
Recheck Cond: (name ~~ '%neusi%'::text)
-> Bitmap Index Scan on idx_trgm (cost=0.00..4.32 rows=24 width=0)
Index Cond: (name ~~ '%neusi%'::text)
(4 rows)
The trigram index deployed in the previous section is also suitable to speed up LIKE. Note that the % symbols can be used at any point in the search string. This is a major advantage over standard B-trees, which just happen to speed up wild cards at the end of the query.
- 基于C語言的程序設(shè)計(jì)
- 21天學(xué)通JavaScript
- Drupal 7 Multilingual Sites
- 塊數(shù)據(jù)5.0:數(shù)據(jù)社會(huì)學(xué)的理論與方法
- 悟透AutoCAD 2009完全自學(xué)手冊(cè)
- 走近大數(shù)據(jù)
- Linux Shell編程從初學(xué)到精通
- Mastering Text Mining with R
- The DevOps 2.1 Toolkit:Docker Swarm
- Mastering MongoDB 3.x
- 電氣控制及Micro800 PLC程序設(shè)計(jì)
- 網(wǎng)絡(luò)信息安全項(xiàng)目教程
- 當(dāng)產(chǎn)品經(jīng)理遇到人工智能
- AVR單片機(jī)C語言程序設(shè)計(jì)實(shí)例精粹
- 巧學(xué)活用AutoCAD