From: Alexander Lakhin <exclusion@gmail.com>
To: pgsql-bugs@lists.postgresql.org, Andrey Borodin <amborodin86@gmail.com>
Subject: Re: BUG #17884: gist_page_items() crashes for a non-leaf page of an index with non-key columns
Date: Fri, 12 May 2023 13:00:01 +0300
Message-ID: <92873f8d-a9b1-0ee8-5753-ee4a1664fb0e@gmail.com> (raw)
In-Reply-To: <17884-cb8c326522977acb@postgresql.org>
References: <17884-cb8c326522977acb@postgresql.org>
04.04.2023 16:00, PG Bug reporting form sent:
> The following bug has been logged on the website:
>
> Bug reference: 17884
>
> ...
>
> Here gist_page_items() tries to decode a tuple using a descriptor of the
> index (defining 3 columns), but in fact non-leaf page items contain no
> non-key data ...
Please look at the patch attached, that makes gist_page_items() process items
on leaf and non-leaf pages differently, accounting for their contents.
I've decided to move away from BuildIndexValueDescription(), but borrow some
of it's code, for two reasons:
that function outputs only key columns;
it checks permissions for a table/index, but this is not needed for pageinspect
(firstly, because a user already has all the data do decode;
secondly, because gist_page_items() requires a superuser role anyway).
Best regards,
Alexander
Attachments:v1-01-fix-gist_page_items-for-index-with-INCLUDE.patch (text/x-patch, 16.3K) downloaddiff --git a/contrib/pageinspect/expected/gist.out b/contrib/pageinspect/expected/gist.outindex 460bef3037..cd10c34960 100644--- a/contrib/pageinspect/expected/gist.out+++ b/contrib/pageinspect/expected/gist.out@@ -107,4 +107,180 @@ SELECT gist_page_opaque_info(decode(repeat('00', :block_size), 'hex'));
(1 row)
+-- Test gist_page_items with pages of an index containing non-key columns+CREATE INDEX test_gist_idx_inc ON test_gist USING gist (p) INCLUDE (t);+SELECT gist_page_items(get_raw_page('test_gist_idx_inc', 0), 'test_gist_idx_inc');+ gist_page_items +------------------------------------------+ (1,"(1,65535)",40,f,"(p)=((156,156))")+ (2,"(2,65535)",40,f,"(p)=((312,312))")+ (3,"(3,65535)",40,f,"(p)=((468,468))")+ (4,"(4,65535)",40,f,"(p)=((624,624))")+ (5,"(5,65535)",40,f,"(p)=((718,718))")+ (6,"(6,65535)",40,f,"(p)=((812,812))")+ (7,"(7,65535)",40,f,"(p)=((906,906))")+ (8,"(8,65535)",40,f,"(p)=((1000,1000))")+(8 rows)++SELECT gist_page_items(get_raw_page('test_gist_idx_inc', 1), 'test_gist_idx_inc');+ gist_page_items +------------------------------------------------------------------+ (1,"(0,1)",48,f,"(p) INCLUDE (t)=((1,1)) INCLUDE (1)")+ (2,"(0,2)",48,f,"(p) INCLUDE (t)=((2,2)) INCLUDE (2)")+ (3,"(0,3)",48,f,"(p) INCLUDE (t)=((3,3)) INCLUDE (3)")+ (4,"(0,4)",48,f,"(p) INCLUDE (t)=((4,4)) INCLUDE (4)")+ (5,"(0,5)",48,f,"(p) INCLUDE (t)=((5,5)) INCLUDE (5)")+ (6,"(0,6)",48,f,"(p) INCLUDE (t)=((6,6)) INCLUDE (6)")+ (7,"(0,7)",48,f,"(p) INCLUDE (t)=((7,7)) INCLUDE (7)")+ (8,"(0,8)",48,f,"(p) INCLUDE (t)=((8,8)) INCLUDE (8)")+ (9,"(0,9)",48,f,"(p) INCLUDE (t)=((9,9)) INCLUDE (9)")+ (10,"(0,10)",48,f,"(p) INCLUDE (t)=((10,10)) INCLUDE (10)")+ (11,"(0,11)",48,f,"(p) INCLUDE (t)=((11,11)) INCLUDE (11)")+ (12,"(0,12)",48,f,"(p) INCLUDE (t)=((12,12)) INCLUDE (12)")+ (13,"(0,13)",48,f,"(p) INCLUDE (t)=((13,13)) INCLUDE (13)")+ (14,"(0,14)",48,f,"(p) INCLUDE (t)=((14,14)) INCLUDE (14)")+ (15,"(0,15)",48,f,"(p) INCLUDE (t)=((15,15)) INCLUDE (15)")+ (16,"(0,16)",48,f,"(p) INCLUDE (t)=((16,16)) INCLUDE (16)")+ (17,"(0,17)",48,f,"(p) INCLUDE (t)=((17,17)) INCLUDE (17)")+ (18,"(0,18)",48,f,"(p) INCLUDE (t)=((18,18)) INCLUDE (18)")+ (19,"(0,19)",48,f,"(p) INCLUDE (t)=((19,19)) INCLUDE (19)")+ (20,"(0,20)",48,f,"(p) INCLUDE (t)=((20,20)) INCLUDE (20)")+ (21,"(0,21)",48,f,"(p) INCLUDE (t)=((21,21)) INCLUDE (21)")+ (22,"(0,22)",48,f,"(p) INCLUDE (t)=((22,22)) INCLUDE (22)")+ (23,"(0,23)",48,f,"(p) INCLUDE (t)=((23,23)) INCLUDE (23)")+ (24,"(0,24)",48,f,"(p) INCLUDE (t)=((24,24)) INCLUDE (24)")+ (25,"(0,25)",48,f,"(p) INCLUDE (t)=((25,25)) INCLUDE (25)")+ (26,"(0,26)",48,f,"(p) INCLUDE (t)=((26,26)) INCLUDE (26)")+ (27,"(0,27)",48,f,"(p) INCLUDE (t)=((27,27)) INCLUDE (27)")+ (28,"(0,28)",48,f,"(p) INCLUDE (t)=((28,28)) INCLUDE (28)")+ (29,"(0,29)",48,f,"(p) INCLUDE (t)=((29,29)) INCLUDE (29)")+ (30,"(0,30)",48,f,"(p) INCLUDE (t)=((30,30)) INCLUDE (30)")+ (31,"(0,31)",48,f,"(p) INCLUDE (t)=((31,31)) INCLUDE (31)")+ (32,"(0,32)",48,f,"(p) INCLUDE (t)=((32,32)) INCLUDE (32)")+ (33,"(0,33)",48,f,"(p) INCLUDE (t)=((33,33)) INCLUDE (33)")+ (34,"(0,34)",48,f,"(p) INCLUDE (t)=((34,34)) INCLUDE (34)")+ (35,"(0,35)",48,f,"(p) INCLUDE (t)=((35,35)) INCLUDE (35)")+ (36,"(0,36)",48,f,"(p) INCLUDE (t)=((36,36)) INCLUDE (36)")+ (37,"(0,37)",48,f,"(p) INCLUDE (t)=((37,37)) INCLUDE (37)")+ (38,"(0,38)",48,f,"(p) INCLUDE (t)=((38,38)) INCLUDE (38)")+ (39,"(0,39)",48,f,"(p) INCLUDE (t)=((39,39)) INCLUDE (39)")+ (40,"(0,40)",48,f,"(p) INCLUDE (t)=((40,40)) INCLUDE (40)")+ (41,"(0,41)",48,f,"(p) INCLUDE (t)=((41,41)) INCLUDE (41)")+ (42,"(0,42)",48,f,"(p) INCLUDE (t)=((42,42)) INCLUDE (42)")+ (43,"(0,43)",48,f,"(p) INCLUDE (t)=((43,43)) INCLUDE (43)")+ (44,"(0,44)",48,f,"(p) INCLUDE (t)=((44,44)) INCLUDE (44)")+ (45,"(0,45)",48,f,"(p) INCLUDE (t)=((45,45)) INCLUDE (45)")+ (46,"(0,46)",48,f,"(p) INCLUDE (t)=((46,46)) INCLUDE (46)")+ (47,"(0,47)",48,f,"(p) INCLUDE (t)=((47,47)) INCLUDE (47)")+ (48,"(0,48)",48,f,"(p) INCLUDE (t)=((48,48)) INCLUDE (48)")+ (49,"(0,49)",48,f,"(p) INCLUDE (t)=((49,49)) INCLUDE (49)")+ (50,"(0,50)",48,f,"(p) INCLUDE (t)=((50,50)) INCLUDE (50)")+ (51,"(0,51)",48,f,"(p) INCLUDE (t)=((51,51)) INCLUDE (51)")+ (52,"(0,52)",48,f,"(p) INCLUDE (t)=((52,52)) INCLUDE (52)")+ (53,"(0,53)",48,f,"(p) INCLUDE (t)=((53,53)) INCLUDE (53)")+ (54,"(0,54)",48,f,"(p) INCLUDE (t)=((54,54)) INCLUDE (54)")+ (55,"(0,55)",48,f,"(p) INCLUDE (t)=((55,55)) INCLUDE (55)")+ (56,"(0,56)",48,f,"(p) INCLUDE (t)=((56,56)) INCLUDE (56)")+ (57,"(0,57)",48,f,"(p) INCLUDE (t)=((57,57)) INCLUDE (57)")+ (58,"(0,58)",48,f,"(p) INCLUDE (t)=((58,58)) INCLUDE (58)")+ (59,"(0,59)",48,f,"(p) INCLUDE (t)=((59,59)) INCLUDE (59)")+ (60,"(0,60)",48,f,"(p) INCLUDE (t)=((60,60)) INCLUDE (60)")+ (61,"(0,61)",48,f,"(p) INCLUDE (t)=((61,61)) INCLUDE (61)")+ (62,"(0,62)",48,f,"(p) INCLUDE (t)=((62,62)) INCLUDE (62)")+ (63,"(0,63)",48,f,"(p) INCLUDE (t)=((63,63)) INCLUDE (63)")+ (64,"(0,64)",48,f,"(p) INCLUDE (t)=((64,64)) INCLUDE (64)")+ (65,"(0,65)",48,f,"(p) INCLUDE (t)=((65,65)) INCLUDE (65)")+ (66,"(0,66)",48,f,"(p) INCLUDE (t)=((66,66)) INCLUDE (66)")+ (67,"(0,67)",48,f,"(p) INCLUDE (t)=((67,67)) INCLUDE (67)")+ (68,"(0,68)",48,f,"(p) INCLUDE (t)=((68,68)) INCLUDE (68)")+ (69,"(0,69)",48,f,"(p) INCLUDE (t)=((69,69)) INCLUDE (69)")+ (70,"(0,70)",48,f,"(p) INCLUDE (t)=((70,70)) INCLUDE (70)")+ (71,"(0,71)",48,f,"(p) INCLUDE (t)=((71,71)) INCLUDE (71)")+ (72,"(0,72)",48,f,"(p) INCLUDE (t)=((72,72)) INCLUDE (72)")+ (73,"(0,73)",48,f,"(p) INCLUDE (t)=((73,73)) INCLUDE (73)")+ (74,"(0,74)",48,f,"(p) INCLUDE (t)=((74,74)) INCLUDE (74)")+ (75,"(0,75)",48,f,"(p) INCLUDE (t)=((75,75)) INCLUDE (75)")+ (76,"(0,76)",48,f,"(p) INCLUDE (t)=((76,76)) INCLUDE (76)")+ (77,"(0,77)",48,f,"(p) INCLUDE (t)=((77,77)) INCLUDE (77)")+ (78,"(0,78)",48,f,"(p) INCLUDE (t)=((78,78)) INCLUDE (78)")+ (79,"(0,79)",48,f,"(p) INCLUDE (t)=((79,79)) INCLUDE (79)")+ (80,"(0,80)",48,f,"(p) INCLUDE (t)=((80,80)) INCLUDE (80)")+ (81,"(0,81)",48,f,"(p) INCLUDE (t)=((81,81)) INCLUDE (81)")+ (82,"(0,82)",48,f,"(p) INCLUDE (t)=((82,82)) INCLUDE (82)")+ (83,"(0,83)",48,f,"(p) INCLUDE (t)=((83,83)) INCLUDE (83)")+ (84,"(0,84)",48,f,"(p) INCLUDE (t)=((84,84)) INCLUDE (84)")+ (85,"(0,85)",48,f,"(p) INCLUDE (t)=((85,85)) INCLUDE (85)")+ (86,"(0,86)",48,f,"(p) INCLUDE (t)=((86,86)) INCLUDE (86)")+ (87,"(0,87)",48,f,"(p) INCLUDE (t)=((87,87)) INCLUDE (87)")+ (88,"(0,88)",48,f,"(p) INCLUDE (t)=((88,88)) INCLUDE (88)")+ (89,"(0,89)",48,f,"(p) INCLUDE (t)=((89,89)) INCLUDE (89)")+ (90,"(0,90)",48,f,"(p) INCLUDE (t)=((90,90)) INCLUDE (90)")+ (91,"(0,91)",48,f,"(p) INCLUDE (t)=((91,91)) INCLUDE (91)")+ (92,"(0,92)",48,f,"(p) INCLUDE (t)=((92,92)) INCLUDE (92)")+ (93,"(0,93)",48,f,"(p) INCLUDE (t)=((93,93)) INCLUDE (93)")+ (94,"(0,94)",48,f,"(p) INCLUDE (t)=((94,94)) INCLUDE (94)")+ (95,"(0,95)",48,f,"(p) INCLUDE (t)=((95,95)) INCLUDE (95)")+ (96,"(0,96)",48,f,"(p) INCLUDE (t)=((96,96)) INCLUDE (96)")+ (97,"(0,97)",48,f,"(p) INCLUDE (t)=((97,97)) INCLUDE (97)")+ (98,"(0,98)",48,f,"(p) INCLUDE (t)=((98,98)) INCLUDE (98)")+ (99,"(0,99)",48,f,"(p) INCLUDE (t)=((99,99)) INCLUDE (99)")+ (100,"(0,100)",48,f,"(p) INCLUDE (t)=((100,100)) INCLUDE (100)")+ (101,"(0,101)",48,f,"(p) INCLUDE (t)=((101,101)) INCLUDE (101)")+ (102,"(0,102)",48,f,"(p) INCLUDE (t)=((102,102)) INCLUDE (102)")+ (103,"(0,103)",48,f,"(p) INCLUDE (t)=((103,103)) INCLUDE (103)")+ (104,"(0,104)",48,f,"(p) INCLUDE (t)=((104,104)) INCLUDE (104)")+ (105,"(0,105)",48,f,"(p) INCLUDE (t)=((105,105)) INCLUDE (105)")+ (106,"(0,106)",48,f,"(p) INCLUDE (t)=((106,106)) INCLUDE (106)")+ (107,"(0,107)",48,f,"(p) INCLUDE (t)=((107,107)) INCLUDE (107)")+ (108,"(0,108)",48,f,"(p) INCLUDE (t)=((108,108)) INCLUDE (108)")+ (109,"(0,109)",48,f,"(p) INCLUDE (t)=((109,109)) INCLUDE (109)")+ (110,"(0,110)",48,f,"(p) INCLUDE (t)=((110,110)) INCLUDE (110)")+ (111,"(0,111)",48,f,"(p) INCLUDE (t)=((111,111)) INCLUDE (111)")+ (112,"(0,112)",48,f,"(p) INCLUDE (t)=((112,112)) INCLUDE (112)")+ (113,"(0,113)",48,f,"(p) INCLUDE (t)=((113,113)) INCLUDE (113)")+ (114,"(0,114)",48,f,"(p) INCLUDE (t)=((114,114)) INCLUDE (114)")+ (115,"(0,115)",48,f,"(p) INCLUDE (t)=((115,115)) INCLUDE (115)")+ (116,"(0,116)",48,f,"(p) INCLUDE (t)=((116,116)) INCLUDE (116)")+ (117,"(0,117)",48,f,"(p) INCLUDE (t)=((117,117)) INCLUDE (117)")+ (118,"(0,118)",48,f,"(p) INCLUDE (t)=((118,118)) INCLUDE (118)")+ (119,"(0,119)",48,f,"(p) INCLUDE (t)=((119,119)) INCLUDE (119)")+ (120,"(0,120)",48,f,"(p) INCLUDE (t)=((120,120)) INCLUDE (120)")+ (121,"(0,121)",48,f,"(p) INCLUDE (t)=((121,121)) INCLUDE (121)")+ (122,"(0,122)",48,f,"(p) INCLUDE (t)=((122,122)) INCLUDE (122)")+ (123,"(0,123)",48,f,"(p) INCLUDE (t)=((123,123)) INCLUDE (123)")+ (124,"(0,124)",48,f,"(p) INCLUDE (t)=((124,124)) INCLUDE (124)")+ (125,"(0,125)",48,f,"(p) INCLUDE (t)=((125,125)) INCLUDE (125)")+ (126,"(0,126)",48,f,"(p) INCLUDE (t)=((126,126)) INCLUDE (126)")+ (127,"(0,127)",48,f,"(p) INCLUDE (t)=((127,127)) INCLUDE (127)")+ (128,"(0,128)",48,f,"(p) INCLUDE (t)=((128,128)) INCLUDE (128)")+ (129,"(0,129)",48,f,"(p) INCLUDE (t)=((129,129)) INCLUDE (129)")+ (130,"(0,130)",48,f,"(p) INCLUDE (t)=((130,130)) INCLUDE (130)")+ (131,"(0,131)",48,f,"(p) INCLUDE (t)=((131,131)) INCLUDE (131)")+ (132,"(0,132)",48,f,"(p) INCLUDE (t)=((132,132)) INCLUDE (132)")+ (133,"(0,133)",48,f,"(p) INCLUDE (t)=((133,133)) INCLUDE (133)")+ (134,"(0,134)",48,f,"(p) INCLUDE (t)=((134,134)) INCLUDE (134)")+ (135,"(0,135)",48,f,"(p) INCLUDE (t)=((135,135)) INCLUDE (135)")+ (136,"(0,136)",48,f,"(p) INCLUDE (t)=((136,136)) INCLUDE (136)")+ (137,"(0,137)",48,f,"(p) INCLUDE (t)=((137,137)) INCLUDE (137)")+ (138,"(0,138)",48,f,"(p) INCLUDE (t)=((138,138)) INCLUDE (138)")+ (139,"(0,139)",48,f,"(p) INCLUDE (t)=((139,139)) INCLUDE (139)")+ (140,"(0,140)",48,f,"(p) INCLUDE (t)=((140,140)) INCLUDE (140)")+ (141,"(0,141)",48,f,"(p) INCLUDE (t)=((141,141)) INCLUDE (141)")+ (142,"(0,142)",48,f,"(p) INCLUDE (t)=((142,142)) INCLUDE (142)")+ (143,"(0,143)",48,f,"(p) INCLUDE (t)=((143,143)) INCLUDE (143)")+ (144,"(0,144)",48,f,"(p) INCLUDE (t)=((144,144)) INCLUDE (144)")+ (145,"(0,145)",48,f,"(p) INCLUDE (t)=((145,145)) INCLUDE (145)")+ (146,"(0,146)",48,f,"(p) INCLUDE (t)=((146,146)) INCLUDE (146)")+ (147,"(0,147)",48,f,"(p) INCLUDE (t)=((147,147)) INCLUDE (147)")+ (148,"(0,148)",48,f,"(p) INCLUDE (t)=((148,148)) INCLUDE (148)")+ (149,"(0,149)",48,f,"(p) INCLUDE (t)=((149,149)) INCLUDE (149)")+ (150,"(0,150)",48,f,"(p) INCLUDE (t)=((150,150)) INCLUDE (150)")+ (151,"(0,151)",48,f,"(p) INCLUDE (t)=((151,151)) INCLUDE (151)")+ (152,"(0,152)",48,f,"(p) INCLUDE (t)=((152,152)) INCLUDE (152)")+ (153,"(0,153)",48,f,"(p) INCLUDE (t)=((153,153)) INCLUDE (153)")+ (154,"(0,154)",48,f,"(p) INCLUDE (t)=((154,154)) INCLUDE (154)")+ (155,"(0,155)",48,f,"(p) INCLUDE (t)=((155,155)) INCLUDE (155)")+ (156,"(0,156)",48,f,"(p) INCLUDE (t)=((156,156)) INCLUDE (156)")+(156 rows)+
DROP TABLE test_gist;
diff --git a/contrib/pageinspect/gistfuncs.c b/contrib/pageinspect/gistfuncs.cindex 3dca7f1318..422290311c 100644--- a/contrib/pageinspect/gistfuncs.c+++ b/contrib/pageinspect/gistfuncs.c@@ -24,6 +24,8 @@
#include "utils/rel.h"
#include "utils/pg_lsn.h"
#include "utils/varlena.h"
+#include "utils/ruleutils.h"+#include "utils/lsyscache.h"
PG_FUNCTION_INFO_V1(gist_page_opaque_info);
PG_FUNCTION_INFO_V1(gist_page_items);
@@ -198,9 +200,12 @@ gist_page_items(PG_FUNCTION_ARGS)
Oid indexRelid = PG_GETARG_OID(1);
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
Relation indexRel;
+ TupleDesc tupdesc;
Page page;
+ uint16 flagbits;
OffsetNumber offset;
OffsetNumber maxoff = InvalidOffsetNumber;
+ char *index_columns;
if (!superuser())
ereport(ERROR,
@@ -226,6 +231,19 @@ gist_page_items(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}
+ flagbits = GistPageGetOpaque(page)->flags;+ if (flagbits & F_LEAF)+ {+ tupdesc = RelationGetDescr(indexRel);+ index_columns = pg_get_indexdef_columns_with_included(indexRelid, true);+ }+ else+ {+ tupdesc = CreateTupleDescCopy(RelationGetDescr(indexRel));+ tupdesc->natts = IndexRelationGetNumberOfKeyAttributes(indexRel);+ index_columns = pg_get_indexdef_columns(indexRelid, true);+ }+
/* Avoid bogus PageGetMaxOffsetNumber() call with deleted pages */
if (GistPageIsDeleted(page))
elog(NOTICE, "page is deleted");
@@ -242,7 +260,8 @@ gist_page_items(PG_FUNCTION_ARGS)
IndexTuple itup;
Datum itup_values[INDEX_MAX_KEYS];
bool itup_isnull[INDEX_MAX_KEYS];
- char *key_desc;+ StringInfoData buf;+ int i;
id = PageGetItemId(page, offset);
@@ -251,7 +270,7 @@ gist_page_items(PG_FUNCTION_ARGS)
itup = (IndexTuple) PageGetItem(page, id);
- index_deform_tuple(itup, RelationGetDescr(indexRel),+ index_deform_tuple(itup, tupdesc,
itup_values, itup_isnull);
memset(nulls, 0, sizeof(nulls));
@@ -261,9 +280,56 @@ gist_page_items(PG_FUNCTION_ARGS)
values[2] = Int32GetDatum((int) IndexTupleSize(itup));
values[3] = BoolGetDatum(ItemIdIsDead(id));
- key_desc = BuildIndexValueDescription(indexRel, itup_values, itup_isnull);- if (key_desc)- values[4] = CStringGetTextDatum(key_desc);+ if (index_columns)+ {+ initStringInfo(&buf);+ appendStringInfo(&buf, "(%s)=(", index_columns);++ for (i = 0; i < tupdesc->natts; i++)+ {+ char *val;++ if (itup_isnull[i])+ val = "null";+ else+ {+ Oid foutoid;+ bool typisvarlena;++ if (i < IndexRelationGetNumberOfKeyAttributes(indexRel))+ {+ /*+ * Use rd_opcintype for key columns as in+ * BuildIndexValueDescription().+ */+ getTypeOutputInfo(indexRel->rd_opcintype[i],+ &foutoid, &typisvarlena);+ }+ else+ {+ getTypeOutputInfo(tupdesc->attrs[i].atttypid,+ &foutoid, &typisvarlena);+ }+ val = OidOutputFunctionCall(foutoid, itup_values[i]);+ }++ if (i == IndexRelationGetNumberOfKeyAttributes(indexRel))+ {+ appendStringInfoString(&buf, ") INCLUDE (");+ }+ else if (i > 0)+ {+ appendStringInfoString(&buf, ", ");+ }++ appendStringInfoString(&buf, val);+ }++ appendStringInfoChar(&buf, ')');++ values[4] = CStringGetTextDatum(buf.data);+ nulls[4] = false;+ }
else
{
values[4] = (Datum) 0;
diff --git a/contrib/pageinspect/sql/gist.sql b/contrib/pageinspect/sql/gist.sqlindex 4787b784a4..16cc14bcac 100644--- a/contrib/pageinspect/sql/gist.sql+++ b/contrib/pageinspect/sql/gist.sql@@ -52,4 +52,9 @@ SELECT gist_page_items_bytea(decode(repeat('00', :block_size), 'hex'));
SELECT gist_page_items(decode(repeat('00', :block_size), 'hex'), 'test_gist_idx'::regclass);
SELECT gist_page_opaque_info(decode(repeat('00', :block_size), 'hex'));
+-- Test gist_page_items with pages of an index containing non-key columns+CREATE INDEX test_gist_idx_inc ON test_gist USING gist (p) INCLUDE (t);+SELECT gist_page_items(get_raw_page('test_gist_idx_inc', 0), 'test_gist_idx_inc');+SELECT gist_page_items(get_raw_page('test_gist_idx_inc', 1), 'test_gist_idx_inc');+
DROP TABLE test_gist;
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.cindex 60f9d08d5d..71f650868a 100644--- a/src/backend/utils/adt/ruleutils.c+++ b/src/backend/utils/adt/ruleutils.c@@ -1215,6 +1215,20 @@ pg_get_indexdef_columns(Oid indexrelid, bool pretty)
prettyFlags, false);
}
+/* Internal version that reports also the non-key-column definitions */+char *+pg_get_indexdef_columns_with_included(Oid indexrelid, bool pretty)+{+ int prettyFlags;++ prettyFlags = GET_PRETTY_FLAGS(pretty);++ return pg_get_indexdef_worker(indexrelid, 0, NULL,+ true, false,+ false, false,+ prettyFlags, false);+}+
/*
* Internal workhorse to decompile an index definition.
*
diff --git a/src/include/utils/ruleutils.h b/src/include/utils/ruleutils.hindex 1a42d9f39b..d221724cc1 100644--- a/src/include/utils/ruleutils.h+++ b/src/include/utils/ruleutils.h@@ -23,6 +23,8 @@ struct PlannedStmt;
extern char *pg_get_indexdef_string(Oid indexrelid);
extern char *pg_get_indexdef_columns(Oid indexrelid, bool pretty);
+extern char *pg_get_indexdef_columns_with_included(Oid indexrelid,+ bool pretty);
extern char *pg_get_querydef(Query *query, bool pretty);
extern char *pg_get_partkeydef_columns(Oid relid, bool pretty);
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: exclusion@gmail.com, amborodin86@gmail.com
Subject: Re: BUG #17884: gist_page_items() crashes for a non-leaf page of an index with non-key columns
In-Reply-To: <92873f8d-a9b1-0ee8-5753-ee4a1664fb0e@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox