Re: index question

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com>
Cc: Melvin Davidson <melvin6925(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: index question
Date: 2016-05-02 15:23:21
Message-ID: CAKFQuwYMoS2AbFWnHCAxFTbLxQSOaRA8AkvErEKFShz+s3wfPw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, May 2, 2016 at 8:16 AM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Sun, May 1, 2016 at 7:27 PM, drum(dot)lucas(at)gmail(dot)com <drum(dot)lucas(at)gmail(dot)com
> > wrote:
>
> ​Repeating the query to improve the self-containment aspect of the email
> would have been appreciated.
> ​
>
>>
>> if possible please have a look on the explain analyze results:
>>
>> http://explain.depesz.com/s/rHOU
>>
>> What else can I do?
>>
>> *The indexes I created is:*
>> - CREATE INDEX CONCURRENTLY ix_inode_segments_notes_clientids2 ON
>> gorfs.inode_segments USING btree ("full_path");
>>
>>
> ​the only condition that could even potentially use this index​ is:
>
> s.full_path ~ '/userfiles/account/[0-9]+/[a-z]+/[0-9]+'
>
> My knowledge is limited in this area, and the documentation covers this
> specific dynamic only minimally, but for certain attempting to perform an
> un-anchored regexp match using a btree index is impossible.
>
> These leaves to avenues to explore.
>
> 1) See if a start-of-string anchor will make the btree index usable
> 2) Use the pg_trgm contrib module
>
> http://www.postgresql.org/docs/current/static/pgtrgm.html
>
> - CREATE INDEX CONCURRENTLY ix_inodes_checksum_st_size ON gorfs.inodes
>> USING btree ("checksum_md5","st_size");
>>
> ​
> This one was used.​
>
> ​IMO you are leaving too much infomation encoded in the full_path. I'd
> personally setup triggers to parse out the components on insert/update into
> fields and then index those fields. In fact I'd probably use some form of
> inheritance or other one-to-one relationship here.
>
>
I guess it is documented, I just needed to look a bit more.

​"""
The optimizer can also use a B-tree index for queries involving the pattern
matching operators LIKE and ~ if the pattern is a constant and is anchored
to the beginning of the string — for example, col LIKE 'foo%' or col ~
'^foo', but not col LIKE '%bar'. However, if your database does not use the
C locale you will need to create the index with a special operator class to
support indexing of pattern-matching queries; see Section 11.9 below. It is
also possible to use B-tree indexes for ILIKE and ~*, but only if the
pattern starts with non-alphabetic characters, i.e., characters that are
not affected by upper/lower case conversion.
​"""

http://www.postgresql.org/docs/current/static/indexes-types.html

​David J.​

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message drum.lucas@gmail.com 2016-05-02 19:44:51 Re: index question
Previous Message David G. Johnston 2016-05-02 15:16:40 Re: index question