From: | Amit Langote <amitlangote09(at)gmail(dot)com> |
---|---|
To: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
Cc: | Larry White <ljw1001(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Is it possible to create an index without keeping the indexed data in a column? |
Date: | 2014-08-01 05:50:03 |
Message-ID: | CA+HiwqHMgmp2HnxPzzhtbm+guj2Nih-Hw8MtJUJHL7Gw-2RfWQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Aug 1, 2014 at 10:48 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Fri, Aug 1, 2014 at 4:47 AM, Larry White <ljw1001(at)gmail(dot)com> wrote:
>> Is there a way to get Postgres to index the table as if the JSON were there,
>> but not actually put the data in the table?
>> I could either store the docs
>> elsewhere and keep a reference, or compress them and put them in the table
>> in compressed form as a blob.
> No. This is equivalent to the creation of an index on a foreign table.
Not sure exactly if it applies here; but I seem to recall reading
somewhere that you can index "generated" columns. Something like
following (this example is similar what I recall seeing there)
postgres=# CREATE TABLE test(a, b) AS SELECT md5(g::text)::char(10),
md5(g::text)::char(5) FROM generate_series(1, 100000) g;
SELECT 100000
postgres=# CREATE OR REPLACE FUNCTION ab(rec test) RETURNS text AS $$
SELECT rec.a || rec.b; $$ STABLE LANGUAGE SQL;
CREATE FUNCTION
postgres=# CREATE EXTENSION pg_trgm;
CREATE EXTENSION
postgres=# CREATE INDEX test_idx ON test USING GIN (ab(test) gin_trgm_ops);
CREATE INDEX
postgres=# EXPLAIN SELECT * FROM test WHERE ab(test) LIKE '%c4c%';
QUERY PLAN
-------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=16.09..52.53 rows=10 width=17)
Recheck Cond: (((a)::text || (b)::text) ~~ '%c4c%'::text)
-> Bitmap Index Scan on test_idx (cost=0.00..16.08 rows=10 width=0)
Index Cond: (((a)::text || (b)::text) ~~ '%c4c%'::text)
Planning time: 0.361 ms
(5 rows)
--
Amit
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Langote | 2014-08-01 06:02:08 | Re: Is it possible to create an index without keeping the indexed data in a column? |
Previous Message | Larry White | 2014-08-01 04:42:22 | Re: Very Limited Toast Compression on JSONB (9.4 beta 2) |