- 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.
推薦閱讀
- Google Cloud Platform Cookbook
- ServiceNow Cookbook
- Zabbix Network Monitoring(Second Edition)
- 自動化控制工程設(shè)計
- 智能工業(yè)報警系統(tǒng)
- AWS Administration Cookbook
- 傳感器與物聯(lián)網(wǎng)技術(shù)
- 信息物理系統(tǒng)(CPS)測試與評價技術(shù)
- 菜鳥起飛系統(tǒng)安裝與重裝
- Hands-On Reactive Programming with Reactor
- 中國戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·增材制造
- PyTorch深度學(xué)習(xí)
- 軟件測試設(shè)計
- ASP.NET學(xué)習(xí)手冊
- Orange'S:一個操作系統(tǒng)的實現(xiàn)