Skip to content

Commit a9615a4

Browse files
committed
Remove unnecessary TimescaleDB functions
Functions `ts_catalog_open_indexes` and friends are just a copy of the corresponding PostgreSQL function `CatalogOpenIndexes`, so remove them and use these instead.
1 parent fc827c1 commit a9615a4

File tree

5 files changed

+17
-35
lines changed

5 files changed

+17
-35
lines changed

src/ts_catalog/catalog.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -789,28 +789,6 @@ ts_catalog_scan_all(CatalogTable table, int indexid, ScanKeyData *scankey, int n
789789
ts_scanner_scan(&scanctx);
790790
}
791791

792-
extern TSDLLEXPORT ResultRelInfo *
793-
ts_catalog_open_indexes(Relation heapRel)
794-
{
795-
ResultRelInfo *resultRelInfo;
796-
797-
resultRelInfo = makeNode(ResultRelInfo);
798-
resultRelInfo->ri_RangeTableIndex = 0; /* dummy */
799-
resultRelInfo->ri_RelationDesc = heapRel;
800-
resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
801-
802-
ExecOpenIndices(resultRelInfo, false);
803-
804-
return resultRelInfo;
805-
}
806-
807-
extern TSDLLEXPORT void
808-
ts_catalog_close_indexes(ResultRelInfo *indstate)
809-
{
810-
ExecCloseIndices(indstate);
811-
pfree(indstate);
812-
}
813-
814792
/*
815793
* Copied verbatim from postgres source CatalogIndexInsert which is static
816794
* in postgres source code.

src/ts_catalog/catalog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,6 @@ extern TSDLLEXPORT void ts_catalog_update(Relation rel, HeapTuple tuple);
13561356
extern TSDLLEXPORT void ts_catalog_delete_tid_only(Relation rel, ItemPointer tid);
13571357
extern TSDLLEXPORT void ts_catalog_delete_tid(Relation rel, ItemPointer tid);
13581358
extern TSDLLEXPORT void ts_catalog_invalidate_cache(Oid catalog_relid, CmdType operation);
1359-
extern TSDLLEXPORT ResultRelInfo *ts_catalog_open_indexes(Relation heapRel);
1360-
extern TSDLLEXPORT void ts_catalog_close_indexes(ResultRelInfo *indstate);
13611359
extern TSDLLEXPORT void ts_catalog_index_insert(ResultRelInfo *indstate, HeapTuple heapTuple);
13621360

13631361
bool TSDLLEXPORT ts_catalog_scan_one(CatalogTable table, int indexid, ScanKeyData *scankey,

tsl/src/compression/api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <access/xact.h>
1414
#include <catalog/dependency.h>
1515
#include <catalog/index.h>
16+
#include <catalog/indexing.h>
1617
#include <commands/event_trigger.h>
1718
#include <commands/tablecmds.h>
1819
#include <commands/trigger.h>
@@ -1082,10 +1083,9 @@ get_compressed_chunk_index_for_recompression(Chunk *uncompressed_chunk)
10821083

10831084
CompressionSettings *settings = ts_compression_settings_get(compressed_chunk->table_id);
10841085

1085-
ResultRelInfo *indstate = ts_catalog_open_indexes(compressed_chunk_rel);
1086+
CatalogIndexState indstate = CatalogOpenIndexes(compressed_chunk_rel);
10861087
Oid index_oid = get_compressed_chunk_index(indstate, settings);
1087-
1088-
ts_catalog_close_indexes(indstate);
1088+
CatalogCloseIndexes(indstate);
10891089

10901090
table_close(compressed_chunk_rel, NoLock);
10911091
table_close(uncompressed_chunk_rel, NoLock);

tsl/src/compression/compression.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <postgres.h>
77
#include <catalog/heap.h>
8+
#include <catalog/indexing.h>
89
#include <catalog/pg_am.h>
910
#include <common/base64.h>
1011
#include <libpq/pqformat.h>
@@ -793,7 +794,7 @@ row_compressor_init(CompressionSettings *settings, RowCompressor *row_compressor
793794
ALLOCSET_DEFAULT_SIZES),
794795
.compressed_table = compressed_table,
795796
.bistate = need_bistate ? GetBulkInsertState() : NULL,
796-
.resultRelInfo = ts_catalog_open_indexes(compressed_table),
797+
.resultRelInfo = CatalogOpenIndexes(compressed_table),
797798
.n_input_columns = RelationGetDescr(uncompressed_table)->natts,
798799
.count_metadata_column_offset = AttrNumberGetAttrOffset(count_metadata_column_num),
799800
.compressed_values = palloc(sizeof(Datum) * num_columns_in_compressed_table),
@@ -1124,7 +1125,7 @@ row_compressor_close(RowCompressor *row_compressor)
11241125
{
11251126
if (row_compressor->bistate)
11261127
FreeBulkInsertState(row_compressor->bistate);
1127-
ts_catalog_close_indexes(row_compressor->resultRelInfo);
1128+
CatalogCloseIndexes(row_compressor->resultRelInfo);
11281129
}
11291130

11301131
/******************
@@ -1216,7 +1217,7 @@ build_decompressor(Relation in_rel, Relation out_rel)
12161217

12171218
.out_desc = out_desc,
12181219
.out_rel = out_rel,
1219-
.indexstate = ts_catalog_open_indexes(out_rel),
1220+
.indexstate = CatalogOpenIndexes(out_rel),
12201221

12211222
.mycid = GetCurrentCommandId(true),
12221223
.bistate = GetBulkInsertState(),
@@ -1266,7 +1267,7 @@ row_decompressor_close(RowDecompressor *decompressor)
12661267
{
12671268
FreeBulkInsertState(decompressor->bistate);
12681269
MemoryContextDelete(decompressor->per_compressed_row_ctx);
1269-
ts_catalog_close_indexes(decompressor->indexstate);
1270+
CatalogCloseIndexes(decompressor->indexstate);
12701271
FreeExecutorState(decompressor->estate);
12711272
detoaster_close(&decompressor->detoaster);
12721273
}
@@ -1551,11 +1552,15 @@ row_decompressor_decompress_row_to_table(RowDecompressor *decompressor)
15511552
* insert the entire batch into one index, then into another, and so on.
15521553
* Working with one index at a time gives better data access locality,
15531554
* which reduces the load on shared buffers cache.
1555+
*
15541556
* The normal Postgres code inserts each row into all indexes, so to do it
15551557
* the other way around, we create a temporary ResultRelInfo that only
1556-
* references one index. Then we loop over indexes, and for each index we
1557-
* set it to this temporary ResultRelInfo, and insert all rows into this
1558-
* single index.
1558+
* references one index. We need to re-open the index for the relation
1559+
* here since the size of ResultRelInfo can change (this happened in 17.1)
1560+
* and a blind copy of the ResultRelInfo will not copy the correct data.
1561+
*
1562+
* Then we loop over indexes, and for each index we set it to this
1563+
* temporary ResultRelInfo, and insert all rows into this single index.
15591564
*/
15601565
if (decompressor->indexstate->ri_NumIndices > 0)
15611566
{

tsl/src/compression/compression.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#pragma once
77

88
#include <postgres.h>
9+
#include <catalog/indexing.h>
910
#include <executor/tuptable.h>
1011
#include <fmgr.h>
1112
#include <lib/stringinfo.h>
@@ -130,7 +131,7 @@ typedef struct RowDecompressor
130131

131132
TupleDesc out_desc;
132133
Relation out_rel;
133-
ResultRelInfo *indexstate;
134+
CatalogIndexState indexstate;
134135
EState *estate;
135136

136137
CommandId mycid;

0 commit comments

Comments
 (0)