Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b72a723

Browse files
committed
Made storage.c work with PostgreSQL 10
1 parent 00f16af commit b72a723

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

storage.c

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ static ArrayType *form_vector(double *vector, int nrows);
1818
static bool my_simple_heap_update(Relation relation,
1919
ItemPointer otid,
2020
HeapTuple tup);
21+
static bool my_index_insert(Relation indexRelation,
22+
Datum *values, bool *isnull,
23+
ItemPointer heap_t_ctid,
24+
Relation heapRelation,
25+
IndexUniqueCheck checkUnique);
2126

2227

2328
/*
@@ -125,11 +130,11 @@ add_query(int query_hash, bool learn_aqo, bool use_aqo,
125130
PG_TRY();
126131
{
127132
simple_heap_insert(aqo_queries_heap, tuple);
128-
index_insert(query_index_rel,
129-
values, nulls,
130-
&(tuple->t_self),
131-
aqo_queries_heap,
132-
UNIQUE_CHECK_YES);
133+
my_index_insert(query_index_rel,
134+
values, nulls,
135+
&(tuple->t_self),
136+
aqo_queries_heap,
137+
UNIQUE_CHECK_YES);
133138
}
134139
PG_CATCH();
135140
{
@@ -206,8 +211,8 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
206211
values, nulls, do_replace);
207212
if (my_simple_heap_update(aqo_queries_heap, &(nw_tuple->t_self), nw_tuple))
208213
{
209-
index_insert(query_index_rel, values, nulls, &(nw_tuple->t_self),
210-
aqo_queries_heap, UNIQUE_CHECK_YES);
214+
my_index_insert(query_index_rel, values, nulls, &(nw_tuple->t_self),
215+
aqo_queries_heap, UNIQUE_CHECK_YES);
211216
}
212217
else
213218
{
@@ -270,11 +275,11 @@ add_query_text(int query_hash, const char *query_text)
270275
PG_TRY();
271276
{
272277
simple_heap_insert(aqo_query_texts_heap, tuple);
273-
index_insert(query_index_rel,
274-
values, nulls,
275-
&(tuple->t_self),
276-
aqo_query_texts_heap,
277-
UNIQUE_CHECK_YES);
278+
my_index_insert(query_index_rel,
279+
values, nulls,
280+
&(tuple->t_self),
281+
aqo_query_texts_heap,
282+
UNIQUE_CHECK_YES);
278283
}
279284
PG_CATCH();
280285
{
@@ -475,8 +480,8 @@ update_fss(int fss_hash, int nrows, int ncols, double **matrix, double *targets,
475480
PG_TRY();
476481
{
477482
simple_heap_insert(aqo_data_heap, tuple);
478-
index_insert(data_index_rel, values, nulls, &(tuple->t_self),
479-
aqo_data_heap, UNIQUE_CHECK_YES);
483+
my_index_insert(data_index_rel, values, nulls, &(tuple->t_self),
484+
aqo_data_heap, UNIQUE_CHECK_YES);
480485
}
481486
PG_CATCH();
482487
{
@@ -494,8 +499,8 @@ update_fss(int fss_hash, int nrows, int ncols, double **matrix, double *targets,
494499
values, nulls, do_replace);
495500
if (my_simple_heap_update(aqo_data_heap, &(nw_tuple->t_self), nw_tuple))
496501
{
497-
index_insert(data_index_rel, values, nulls, &(nw_tuple->t_self),
498-
aqo_data_heap, UNIQUE_CHECK_YES);
502+
my_index_insert(data_index_rel, values, nulls, &(nw_tuple->t_self),
503+
aqo_data_heap, UNIQUE_CHECK_YES);
499504
}
500505
else
501506
{
@@ -680,8 +685,8 @@ update_aqo_stat(int query_hash, QueryStat * stat)
680685
PG_TRY();
681686
{
682687
simple_heap_insert(aqo_stat_heap, tuple);
683-
index_insert(stat_index_rel, values, nulls, &(tuple->t_self),
684-
aqo_stat_heap, UNIQUE_CHECK_YES);
688+
my_index_insert(stat_index_rel, values, nulls, &(tuple->t_self),
689+
aqo_stat_heap, UNIQUE_CHECK_YES);
685690
}
686691
PG_CATCH();
687692
{
@@ -696,8 +701,8 @@ update_aqo_stat(int query_hash, QueryStat * stat)
696701
values, nulls, do_replace);
697702
if (my_simple_heap_update(aqo_stat_heap, &(nw_tuple->t_self), nw_tuple))
698703
{
699-
index_insert(stat_index_rel, values, nulls, &(nw_tuple->t_self),
700-
aqo_stat_heap, UNIQUE_CHECK_YES);
704+
my_index_insert(stat_index_rel, values, nulls, &(nw_tuple->t_self),
705+
aqo_stat_heap, UNIQUE_CHECK_YES);
701706
}
702707
else
703708
{
@@ -855,6 +860,24 @@ my_simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
855860
}
856861
}
857862

863+
864+
/* Provides correct insert in both PostgreQL 9.6.X and 10.X.X */
865+
static bool
866+
my_index_insert(Relation indexRelation,
867+
Datum *values, bool *isnull,
868+
ItemPointer heap_t_ctid,
869+
Relation heapRelation,
870+
IndexUniqueCheck checkUnique)
871+
{
872+
#if PG_VERSION_NUM < 100000
873+
return index_insert(indexRelation, values, isnull, heap_t_ctid,
874+
heapRelation, checkUnique);
875+
#else
876+
return index_insert(indexRelation, values, isnull, heap_t_ctid,
877+
heapRelation, checkUnique, NULL);
878+
#endif
879+
}
880+
858881
/* Creates a storage for hashes of deactivated queries */
859882
void
860883
init_deactivated_queries_storage(void)

0 commit comments

Comments
 (0)