下载吧 - 绿色安全的游戏和软件下载中心

软件下载吧

当前位置:软件下载吧 > 技术开发 > 数据库 > postgresql 数据库基础 关于like%xxx% 全模糊匹配 的优化操作

postgresql 数据库基础 关于like%xxx% 全模糊匹配 的优化操作

时间:2024-02-07 12:09作者:下载吧人气:25

任何一个关系型数据库关于模糊匹配(like)的优化都是一件痛苦的事,相对而言,诸如like ‘abc%’之类的还好一点,可以通过创建索引来优化,但对于like ‘c%’之类的,真的就没有办法了。

这里介绍一种postgresql关于like ‘c%’的优化方法,是基于全文检索的特性来实现的。

测试数据准备(环境centos6.5 + postgresql 9.6.1)。

postgres=# create table ts(id int,name text);
CREATE TABLE
postgres=# d ts
Table “public.ts”
Column | Type | Modifiers
——–+———+———–
id | integer |
name | text |
postgres=# insert into ts select n,n||’_pjy’ from generate_series(1,2000) n;
INSERT 0 2000
postgres=# insert into ts select n,n||’_mdh’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_lmm’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_syf’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_wbd’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_hhh’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_sjw’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_jjs’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_ymd’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_biu’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# insert into ts select n,n||’_dfl’ from generate_series(1,2000000) n;
INSERT 0 2000000
postgres=# select count(*) from ts;
count
———-
20002000
(1 row)

标签MySQL,技术文档,数据库,PostgreSQL

相关下载

查看所有评论+

网友评论

网友
您的评论需要经过审核才能显示

热门阅览

最新排行

公众号