- 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.
- Practical Data Analysis
- 三菱FX3U/5U PLC從入門到精通
- R Machine Learning By Example
- 自動控制原理
- Photoshop CS3特效處理融會貫通
- 基于32位ColdFire構建嵌入式系統
- Windows Server 2003系統安全管理
- 學練一本通:51單片機應用技術
- MongoDB 4 Quick Start Guide
- Instant Slic3r
- 樂高創意機器人教程(中級 上冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- 精通ROS機器人編程(原書第2版)
- 網管員世界2009超值精華本
- 工程地質地學信息遙感自動提取技術
- 運動控制器及數控系統的工程應用