summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2024-05-01 13:23:05 +1200
committerDavid Rowley <drowley@postgresql.org>2024-05-01 13:23:05 +1200
commit0a34bcd0c23e7f67daad7b026320a12c52d797ac (patch)
tree2dc7670da55694fb9ebee35f225486c220861bdd /src/include
parent1ee22d1e87b3c442928abe9535d6b2bf8460fc67 (diff)
Ensure we allocate NAMEDATALEN bytes for names in Index Only Scans
As an optimization, we store "name" columns as cstrings in btree indexes. Here we modify it so that Index Only Scans convert these cstrings back to names with NAMEDATALEN bytes rather than storing the cstring in the tuple slot, as was happening previously. Bug: #17855 Reported-by: Alexander Lakhin Reviewed-by: Alexander Lakhin, Tom Lane Discussion: https://postgr.es/m/17855-5f523e0f9769a566@postgresql.org Backpatch-through: 12, all supported versions
Diffstat (limited to 'src/include')
-rw-r--r--src/include/catalog/pg_opclass.dat7
-rw-r--r--src/include/nodes/execnodes.h4
2 files changed, 9 insertions, 2 deletions
diff --git a/src/include/catalog/pg_opclass.dat b/src/include/catalog/pg_opclass.dat
index f2342bb328c..8e5a259684e 100644
--- a/src/include/catalog/pg_opclass.dat
+++ b/src/include/catalog/pg_opclass.dat
@@ -91,8 +91,11 @@
# Here's an ugly little hack to save space in the system catalog indexes.
# btree doesn't ordinarily allow a storage type different from input type;
# but cstring and name are the same thing except for trailing padding,
-# and we can safely omit that within an index entry. So we declare the
-# btree opclass for name as using cstring storage type.
+# so we choose to omit that within an index entry. Here we declare the
+# btree opclass for name as using cstring storage type. This does require
+# that we pad the cstring out with the full NAMEDATALEN bytes when performing
+# index-only scans. See corresponding hacks in ExecInitIndexOnlyScan() and
+# StoreIndexTuple().
{ opcmethod => 'btree', opcname => 'name_ops', opcfamily => 'btree/text_ops',
opcintype => 'name', opckeytype => 'cstring' },
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index caf0d41f0bb..d05ec67231f 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -1484,6 +1484,8 @@ typedef struct IndexScanState
* TableSlot slot for holding tuples fetched from the table
* VMBuffer buffer in use for visibility map testing, if any
* PscanLen size of parallel index-only scan descriptor
+ * NameCStringAttNums attnums of name typed columns to pad to NAMEDATALEN
+ * NameCStringCount number of elements in the NameCStringAttNums array
* ----------------
*/
typedef struct IndexOnlyScanState
@@ -1503,6 +1505,8 @@ typedef struct IndexOnlyScanState
TupleTableSlot *ioss_TableSlot;
Buffer ioss_VMBuffer;
Size ioss_PscanLen;
+ AttrNumber *ioss_NameCStringAttNums;
+ int ioss_NameCStringCount;
} IndexOnlyScanState;
/* ----------------