Skip to content

Commit 2ef085d

Browse files
committed
Get rid of pg_class.reltoastidxid.
Treat TOAST index just the same as normal one and get the OID of TOAST index from pg_index but not pg_class.reltoastidxid. This change allows us to handle multiple TOAST indexes, and which is required infrastructure for upcoming REINDEX CONCURRENTLY feature. Patch by Michael Paquier, reviewed by Andres Freund and me.
1 parent f71939c commit 2ef085d

File tree

21 files changed

+333
-163
lines changed

21 files changed

+333
-163
lines changed

contrib/pg_upgrade/info.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,19 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
321321
"INSERT INTO info_rels "
322322
"SELECT reltoastrelid "
323323
"FROM info_rels i JOIN pg_catalog.pg_class c "
324-
" ON i.reloid = c.oid"));
324+
" ON i.reloid = c.oid "
325+
" AND c.reltoastrelid != %u", InvalidOid));
325326
PQclear(executeQueryOrDie(conn,
326327
"INSERT INTO info_rels "
327-
"SELECT reltoastidxid "
328-
"FROM info_rels i JOIN pg_catalog.pg_class c "
329-
" ON i.reloid = c.oid"));
328+
"SELECT indexrelid "
329+
"FROM pg_index "
330+
"WHERE indisvalid "
331+
" AND indrelid IN (SELECT reltoastrelid "
332+
" FROM info_rels i "
333+
" JOIN pg_catalog.pg_class c "
334+
" ON i.reloid = c.oid "
335+
" AND c.reltoastrelid != %u)",
336+
InvalidOid));
330337

331338
snprintf(query, sizeof(query),
332339
"SELECT c.oid, n.nspname, c.relname, "

doc/src/sgml/catalogs.sgml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,15 +1744,6 @@
17441744
</entry>
17451745
</row>
17461746

1747-
<row>
1748-
<entry><structfield>reltoastidxid</structfield></entry>
1749-
<entry><type>oid</type></entry>
1750-
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
1751-
<entry>
1752-
For a TOAST table, the OID of its index. 0 if not a TOAST table.
1753-
</entry>
1754-
</row>
1755-
17561747
<row>
17571748
<entry><structfield>relhasindex</structfield></entry>
17581749
<entry><type>bool</type></entry>

doc/src/sgml/diskusage.sgml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
stored. If the table has any columns with potentially-wide values,
2121
there also might be a <acronym>TOAST</> file associated with the table,
2222
which is used to store values too wide to fit comfortably in the main
23-
table (see <xref linkend="storage-toast">). There will be one index on the
24-
<acronym>TOAST</> table, if present. There also might be indexes associated
25-
with the base table. Each table and index is stored in a separate disk
26-
file &mdash; possibly more than one file, if the file would exceed one
27-
gigabyte. Naming conventions for these files are described in <xref
28-
linkend="storage-file-layout">.
23+
table (see <xref linkend="storage-toast">). There will be one valid index
24+
on the <acronym>TOAST</> table, if present. There also might be indexes
25+
associated with the base table. Each table and index is stored in a
26+
separate disk file &mdash; possibly more than one file, if the file would
27+
exceed one gigabyte. Naming conventions for these files are described
28+
in <xref linkend="storage-file-layout">.
2929
</para>
3030

3131
<para>
@@ -44,7 +44,7 @@
4444
<programlisting>
4545
SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'customer';
4646

47-
pg_relation_filepath | relpages
47+
pg_relation_filepath | relpages
4848
----------------------+----------
4949
base/16384/16806 | 60
5050
(1 row)
@@ -65,12 +65,12 @@ FROM pg_class,
6565
FROM pg_class
6666
WHERE relname = 'customer') AS ss
6767
WHERE oid = ss.reltoastrelid OR
68-
oid = (SELECT reltoastidxid
69-
FROM pg_class
70-
WHERE oid = ss.reltoastrelid)
68+
oid = (SELECT indexrelid
69+
FROM pg_index
70+
WHERE indrelid = ss.reltoastrelid)
7171
ORDER BY relname;
7272

73-
relname | relpages
73+
relname | relpages
7474
----------------------+----------
7575
pg_toast_16806 | 0
7676
pg_toast_16806_index | 1
@@ -87,7 +87,7 @@ WHERE c.relname = 'customer' AND
8787
c2.oid = i.indexrelid
8888
ORDER BY c2.relname;
8989

90-
relname | relpages
90+
relname | relpages
9191
----------------------+----------
9292
customer_id_indexdex | 26
9393
</programlisting>
@@ -101,7 +101,7 @@ SELECT relname, relpages
101101
FROM pg_class
102102
ORDER BY relpages DESC;
103103

104-
relname | relpages
104+
relname | relpages
105105
----------------------+----------
106106
bigtable | 3290
107107
customer | 3144

doc/src/sgml/monitoring.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,12 +1163,12 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
11631163
<row>
11641164
<entry><structfield>tidx_blks_read</></entry>
11651165
<entry><type>bigint</></entry>
1166-
<entry>Number of disk blocks read from this table's TOAST table index (if any)</entry>
1166+
<entry>Number of disk blocks read from this table's TOAST table indexes (if any)</entry>
11671167
</row>
11681168
<row>
11691169
<entry><structfield>tidx_blks_hit</></entry>
11701170
<entry><type>bigint</></entry>
1171-
<entry>Number of buffer hits in this table's TOAST table index (if any)</entry>
1171+
<entry>Number of buffer hits in this table's TOAST table indexes (if any)</entry>
11721172
</row>
11731173
</tbody>
11741174
</tgroup>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy