- 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.
- 空間傳感器網(wǎng)絡(luò)復(fù)雜區(qū)域智能監(jiān)測(cè)技術(shù)
- STM32G4入門與電機(jī)控制實(shí)戰(zhàn):基于X-CUBE-MCSDK的無(wú)刷直流電機(jī)與永磁同步電機(jī)控制實(shí)現(xiàn)
- JSF2和RichFaces4使用指南
- 21天學(xué)通Java Web開(kāi)發(fā)
- INSTANT Drools Starter
- 計(jì)算機(jī)與信息技術(shù)基礎(chǔ)上機(jī)指導(dǎo)
- 格蠹匯編
- 電腦上網(wǎng)入門
- Web璀璨:Silverlight應(yīng)用技術(shù)完全指南
- 貫通Hibernate開(kāi)發(fā)
- Kubernetes on AWS
- 伺服與運(yùn)動(dòng)控制系統(tǒng)設(shè)計(jì)
- 玩轉(zhuǎn)PowerPoint
- 工廠電氣控制設(shè)備
- 三維動(dòng)畫(huà)制作(3ds max7.0)