On Wed, Mar 24, 2021 at 3:10 PM Dilip Kumar <dilipbal...@gmail.com> wrote: > > On Wed, Mar 24, 2021 at 2:49 PM Justin Pryzby <pry...@telsasoft.com> wrote: > > > > On Wed, Mar 24, 2021 at 02:24:41PM +0530, Dilip Kumar wrote: > > > On Wed, Mar 24, 2021 at 1:43 PM Dilip Kumar <dilipbal...@gmail.com> wrote: > > > > > create table t1 (col1 text, col2 text); > > > > > create unique index on t1 ((col1 || col2)); > > > > > insert into t1 values((select array_agg(md5(g::text))::text from > > > > > generate_series(1, 256) g), version()); > > > > > > > > > > Attached is a backtrace from current HEAD > > > > > > > > Thanks for reporting this issue. Actually, I missed setting the > > > > attcompression for the expression index and that is causing this > > > > assert. I will send a patch in some time. > > > > > > PFA, patch to fix the issue. > > > > Could you include a test case exercizing this code path ? > > Like Jaime's reproducer. > > I will do that.
0001 ->shows compression method for the index attribute in index describe 0002 -> fix the reported bug (test case included) Apart from this, I was thinking that currently, we are allowing to ALTER SET COMPRESSION only for the table and matview, IMHO it makes sense to allow to alter the compression method for the index column as well? I mean it is just a one-line change, but just wanted to know the opinion from others. It is not required for the storage because indexes can not have a toast table but index attributes can be compressed so it makes sense to allow to alter the compression method. Thought? -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com
From fa3ee05e21af64af86bedcc919488300c4f9a92d Mon Sep 17 00:00:00 2001 From: Dilip Kumar <dilipkumar@localhost.localdomain> Date: Wed, 24 Mar 2021 15:08:14 +0530 Subject: [PATCH v2 1/2] Show compression method in index describe --- src/bin/psql/describe.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index eeac0ef..9d15324 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1897,6 +1897,7 @@ describeOneTableDetails(const char *schemaname, if (pset.sversion >= 140000 && !pset.hide_compression && (tableinfo.relkind == RELKIND_RELATION || + tableinfo.relkind == RELKIND_INDEX || tableinfo.relkind == RELKIND_PARTITIONED_TABLE || tableinfo.relkind == RELKIND_MATVIEW)) { -- 1.8.3.1
From 54edcec2d44cfac01e1c2d20cc413dac57496ca9 Mon Sep 17 00:00:00 2001 From: Dilip Kumar <dilipkumar@localhost.localdomain> Date: Wed, 24 Mar 2021 14:02:06 +0530 Subject: [PATCH v2 2/2] Fix attcompression for index expression columns For expression columns the attcompression was not set. So this patch set it to the default compression method for compressible types otherwise to the invalid compression method. --- src/backend/catalog/index.c | 11 +++++++++++ src/test/regress/expected/compression.out | 13 +++++++++++++ src/test/regress/expected/compression_1.out | 14 ++++++++++++++ src/test/regress/sql/compression.sql | 8 ++++++++ 4 files changed, 46 insertions(+) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 397d70d..b5a79ce 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -30,6 +30,7 @@ #include "access/relscan.h" #include "access/sysattr.h" #include "access/tableam.h" +#include "access/toast_compression.h" #include "access/transam.h" #include "access/visibilitymap.h" #include "access/xact.h" @@ -379,6 +380,16 @@ ConstructTupleDescriptor(Relation heapRelation, to->attalign = typeTup->typalign; to->atttypmod = exprTypmod(indexkey); + /* + * For expression column, if attribute type storage is compressible + * then set the default compression method, otherwise invalid + * compression method. + */ + if (IsStorageCompressible(typeTup->typstorage)) + to->attcompression = GetDefaultToastCompression(); + else + to->attcompression = InvalidCompressionMethod; + ReleaseSysCache(tuple); /* diff --git a/src/test/regress/expected/compression.out b/src/test/regress/expected/compression.out index c2f2e0e..19707fb 100644 --- a/src/test/regress/expected/compression.out +++ b/src/test/regress/expected/compression.out @@ -313,6 +313,19 @@ SELECT pg_column_compression(f1) FROM cmdata; lz4 (2 rows) +-- test expression index +DROP TABLE cmdata2; +CREATE TABLE cmdata2 (f1 TEXT COMPRESSION pglz, f2 TEXT COMPRESSION lz4); +CREATE UNIQUE INDEX idx1 ON cmdata2 ((f1 || f2)); +INSERT INTO cmdata2 VALUES((SELECT array_agg(md5(g::TEXT))::TEXT FROM +generate_series(1, 50) g), VERSION()); +\d+ idx1 + Index "public.idx1" + Column | Type | Key? | Definition | Storage | Compression | Stats target +--------+------+------+------------+----------+-------------+-------------- + expr | text | yes | (f1 || f2) | extended | pglz | +unique, btree, for table "public.cmdata2" + -- check data is ok SELECT length(f1) FROM cmdata; length diff --git a/src/test/regress/expected/compression_1.out b/src/test/regress/expected/compression_1.out index 6626f8e..84b933d 100644 --- a/src/test/regress/expected/compression_1.out +++ b/src/test/regress/expected/compression_1.out @@ -310,6 +310,20 @@ SELECT pg_column_compression(f1) FROM cmdata; pglz (2 rows) +-- test expression index +DROP TABLE cmdata2; +CREATE TABLE cmdata2 (f1 TEXT COMPRESSION pglz, f2 TEXT COMPRESSION lz4); +ERROR: unsupported LZ4 compression method +DETAIL: This functionality requires the server to be built with lz4 support. +HINT: You need to rebuild PostgreSQL using --with-lz4. +CREATE UNIQUE INDEX idx1 ON cmdata2 ((f1 || f2)); +ERROR: relation "cmdata2" does not exist +INSERT INTO cmdata2 VALUES((SELECT array_agg(md5(g::TEXT))::TEXT FROM +generate_series(1, 50) g), VERSION()); +ERROR: relation "cmdata2" does not exist +LINE 1: INSERT INTO cmdata2 VALUES((SELECT array_agg(md5(g::TEXT))::... + ^ +\d+ idx1 -- check data is ok SELECT length(f1) FROM cmdata; length diff --git a/src/test/regress/sql/compression.sql b/src/test/regress/sql/compression.sql index 5e178be..4afd5a2 100644 --- a/src/test/regress/sql/compression.sql +++ b/src/test/regress/sql/compression.sql @@ -130,6 +130,14 @@ SELECT pg_column_compression(f1) FROM cmdata; VACUUM FULL cmdata; SELECT pg_column_compression(f1) FROM cmdata; +-- test expression index +DROP TABLE cmdata2; +CREATE TABLE cmdata2 (f1 TEXT COMPRESSION pglz, f2 TEXT COMPRESSION lz4); +CREATE UNIQUE INDEX idx1 ON cmdata2 ((f1 || f2)); +INSERT INTO cmdata2 VALUES((SELECT array_agg(md5(g::TEXT))::TEXT FROM +generate_series(1, 50) g), VERSION()); +\d+ idx1 + -- check data is ok SELECT length(f1) FROM cmdata; SELECT length(f1) FROM cmdata1; -- 1.8.3.1