From: | Jeff Janes <jeff(dot)janes(at)gmail(dot)com> |
---|---|
To: | Christian Ramseyer <rc(at)networkz(dot)ch> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to speed up pg_trgm / gin index scan |
Date: | 2015-06-22 17:00:38 |
Message-ID: | CAMkU=1xQLU9PzeDTj+32kSc=tCYc2VYZs6rLDNNXKO6U9h9abQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Jun 22, 2015 at 4:51 AM, Christian Ramseyer <rc(at)networkz(dot)ch> wrote:
> Hi
>
> I have a pretty large table with syslog messages.
>
> It is already partitioned by month, and for a single month I have e.g.
>
>
> DM=# \d+ logs_01
>
> Column | Type |
> --------------+-----------------------------+
> host | character varying(255) |
> facility | character varying(10) |
> priority | character varying(10) |
> tag | character varying(255) |
> log_date | timestamp without time zone |
> program | character varying(255) |
> msg | text |
> seq | bigint |
>
> Indexes:
> "logs_01_pkey" PRIMARY KEY, btree (seq)
> "idx_logs_01_lower_host" btree (lower(host::text) varchar_pattern_ops)
> "logs_01_date_index" btree (log_date)
> "tridx_logs_01_msg" gin (msg gin_trgm_ops)
>
>
> DM=# select count(*) from logs_01;
> count
> ----------
> 83052864
>
>
...
> A typical query on this table looks like this:
>
> explain analyze
> select log_date, host, msg
> from logs_01 as log where log.msg like '%192.23.33.177%'
> and log.log_date >= '2015-1-18 1:45:24'
> and log.log_date <= '2015-1-19 1:45:24'
> order by log_date asc offset 200 limit 50;
>
I think that trigram indexes are not well-suited to searching IP addresses.
If the typical query is always an IP address for the LIKE, I think you
would want to build an index specifically tailored to that. You could make
a function to parse the IP address out of the msg, and then make a
functional index, for example. It would require you to write the query
differently. Whether it would be a btree index or a gin index would depend
on whether you can have more than one IP address in a msg.
Cheers,
Jeff
From | Date | Subject | |
---|---|---|---|
Next Message | William Dunn | 2015-06-22 17:06:09 | Re: foreign keys to foreign tables |
Previous Message | Tom Lane | 2015-06-22 16:21:14 | Re: foreign keys to foreign tables |