官术网_书友最值得收藏!

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.
主站蜘蛛池模板: 清原| 林口县| 乾安县| 南投县| 绥阳县| 德州市| 科尔| 多伦县| 贵溪市| 闸北区| 神木县| 自治县| 肇东市| 宿迁市| 新宾| 宁晋县| 天祝| 徐闻县| 连云港市| 安国市| 舞阳县| 苍溪县| 延安市| 金平| 普定县| 鹤山市| 任丘市| 道真| 乐山市| 会东县| 广灵县| 崇明县| 洱源县| 宁武县| 大竹县| 商丘市| 澄城县| 平塘县| 延津县| 临澧县| 宁都县|