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

  • Mastering PostgreSQL 12
  • Hans Jürgen Sch?nig
  • 99字
  • 2021-08-20 10:00:31

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.
主站蜘蛛池模板: 兴义市| 湖南省| 武邑县| 无锡市| 子洲县| 乌什县| 漾濞| 拉孜县| 京山县| 介休市| 大荔县| 鄂温| 吴川市| 柘荣县| 沁源县| 安塞县| 博兴县| 安徽省| 仁寿县| 桐梓县| 通州市| 岳池县| 黑河市| 平南县| 宣武区| 景德镇市| 克东县| 衡山县| 临沧市| 新平| 腾冲县| 宝坻区| 太白县| 深水埗区| 台北市| 崇信县| 和田市| 昌江| 思南县| 晋城| 大足县|