postgresql 数据库数组索引的初步使用

本文介绍了在CentOS7.6环境下安装的PostgreSQL10数据库的详细版本信息,并展示了如何创建和填充一个测试表`tmp_array`,以及建立索引和执行查询分析。通过实验演示了对大规模数据进行查询优化的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

os: centos 7.6.1810
db: postgresql 10

版本

# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core) 

# yum list installed |grep -i postgresql
postgresql10.x86_64                10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-contrib.x86_64        10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-devel.x86_64          10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-docs.x86_64           10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-libs.x86_64           10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-odbc.x86_64           13.00.0000-1PGDG.rhel7              @pgdg10  
postgresql10-plperl.x86_64         10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-plpython.x86_64       10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-plpython3.x86_64      10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-pltcl.x86_64          10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-server.x86_64         10.16-1PGDG.rhel7                   @pgdg10  
postgresql10-tcl.x86_64            2.7.5-1.rhel7                       @pgdg10  
postgresql10-test.x86_64           10.16-1PGDG.rhel7                   @pgdg10

测试

drop table if exists tmp_array;

create table tmp_array (
  id   int8,
  name varchar(100)[]
);


insert into tmp_array
(id,name)
select mod(id,9999) as m_id,
	   array_agg(id::varchar) as m_id_agg
  from generate_series(1,1000000) as id
 group by mod(id,9999)
;

create index idx_tmp_array_x1 on tmp_array using gin(name);

explain ANALYZE
select *
from tmp_array ta
where 1=1
and name @> array['113'::varchar]
;


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据库人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值