Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
针对性能的PostgreSQL表索引_Postgresql_Indexing_Database Performance - Fatal编程技术网

针对性能的PostgreSQL表索引

针对性能的PostgreSQL表索引,postgresql,indexing,database-performance,Postgresql,Indexing,Database Performance,我正在解决PostgreSQL的性能问题,我有下表: CREATE TABLE main_transaction ( id integer NOT NULL DEFAULT nextval('main_transaction_id_seq'::regclass), description character varying(255) NOT NULL, request_no character varying(18), account character varying

我正在解决PostgreSQL的性能问题,我有下表:

 CREATE TABLE main_transaction (
   id integer NOT NULL DEFAULT nextval('main_transaction_id_seq'::regclass),
   description character varying(255) NOT NULL,
   request_no character varying(18),
   account character varying(50),
   ....
 )
上表有34列,包括3个
外键
s,数据超过100万行。我有以下条件
SELECT
query:

SELECT * FROM main_transaction
WHERE upper(request_no) LIKE upper(concat('%','20080417-0258-0697','%'))

在2秒内返回结果。我想通过使用表索引来减少工作时间。到目前为止,我已经使用了
btree
索引。然而,我没有注意到任何快速的结果。我的问题是,如何提高上述查询的性能?

搜索以
%
开头的模式的唯一机会是三元索引:

CREATE EXTENSION pg_trgm;

CREATE INDEX ON main_transaction
   USING gin (upper(request_no) gin_trgm_ops);

搜索以
%
开头的模式的唯一机会是三角图索引:

CREATE EXTENSION pg_trgm;

CREATE INDEX ON main_transaction
   USING gin (upper(request_no) gin_trgm_ops);

为什么
%
?搜索字符串已具有列的最大长度…(“%”,“'20080417-0258-0697',“%”)->((“%”,:字段“%”)为什么
%
?搜索字符串已具有列的最大长度…(“%”,“'20080417-0258-0697',“%”)->((“%”,:字段“%”)太棒了!我的表中也有外键,我使用交叉连接按id链接表,这会导致性能降低。在
profile
表的
main\u transaction
表中,我有一个
profile\u id
列,在profile表中,我有
customer\u id
列,用于
customer
表<代码>从主交易t交叉连接主配置文件p交叉连接主客户c中选择*,其中t.profile_id=p.id和p.user_id=c.id,以及(上部(t.request_no)如上部(concat(“%”,'0-90-6 12',“%”)或上部(c.phone)如上部(concat(“%”,'0-90-6 12',“%”))。谢谢。好吧,那就开始提问吧。这是url:)。伟大的我的表中也有外键,我使用交叉连接按id链接表,这会导致性能降低。在
profile
表的
main\u transaction
表中,我有一个
profile\u id
列,在profile表中,我有
customer\u id
列,用于
customer
表<代码>从主交易t交叉连接主配置文件p交叉连接主客户c中选择*,其中t.profile_id=p.id和p.user_id=c.id,以及(上部(t.request_no)如上部(concat(“%”,'0-90-6 12',“%”)或上部(c.phone)如上部(concat(“%”,'0-90-6 12',“%”))。谢谢。好吧,那就开始提问吧。这是url:)。