- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 100字
- 2021-07-09 19:57:22
Handling regular expressions
However, this is still not everything. Trigram indexes are even capable of speeding up simple regular expressions. The following example shows how this can be done:
test=# SELECT * FROM t_location WHERE name ~ '[A-C].*neu.*';
name
--------------
Bruckneudorf
(1 row)
test=# explain SELECT * FROM t_location WHERE name ~ '[A-C].*neu.*';
QUERY PLAN
-----------------------------------------------------------------
Index Scan using idx_trgm on t_location (cost=0.14..8.16
rows=1 width=13)
Index Cond: (name ~ '[A-C].*neu.*'::text)
(2 rows)
PostgreSQL will inspect the regular expression and use the index to answer the question.
Internally, PostgreSQL can transform the regular expression into a graph and traverse the index accordingly.
推薦閱讀
- ABB工業機器人編程全集
- Visualforce Development Cookbook(Second Edition)
- 輕松學Java
- Learning Apache Cassandra(Second Edition)
- 計算機圖形圖像處理:Photoshop CS3
- Hands-On Cybersecurity with Blockchain
- Creo Parametric 1.0中文版從入門到精通
- Embedded Programming with Modern C++ Cookbook
- Nginx高性能Web服務器詳解
- 網絡服務搭建、配置與管理大全(Linux版)
- 多媒體制作與應用
- 新一代人工智能與語音識別
- Deep Learning Essentials
- 中文版Photoshop情境實訓教程
- 精通ROS機器人編程(原書第2版)