@@ -18,6 +18,11 @@ static ArrayType *form_vector(double *vector, int nrows);
1818static bool my_simple_heap_update (Relation relation ,
1919ItemPointer otid ,
2020HeapTuple 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,
125130PG_TRY ();
126131{
127132simple_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}
134139PG_CATCH ();
135140{
@@ -206,8 +211,8 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
206211values ,nulls ,do_replace );
207212if (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}
212217else
213218{
@@ -270,11 +275,11 @@ add_query_text(int query_hash, const char *query_text)
270275PG_TRY ();
271276{
272277simple_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}
279284PG_CATCH ();
280285{
@@ -475,8 +480,8 @@ update_fss(int fss_hash, int nrows, int ncols, double **matrix, double *targets,
475480PG_TRY ();
476481{
477482simple_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}
481486PG_CATCH ();
482487{
@@ -494,8 +499,8 @@ update_fss(int fss_hash, int nrows, int ncols, double **matrix, double *targets,
494499values ,nulls ,do_replace );
495500if (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}
500505else
501506{
@@ -680,8 +685,8 @@ update_aqo_stat(int query_hash, QueryStat * stat)
680685PG_TRY ();
681686{
682687simple_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}
686691PG_CATCH ();
687692{
@@ -696,8 +701,8 @@ update_aqo_stat(int query_hash, QueryStat * stat)
696701values ,nulls ,do_replace );
697702if (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}
702707else
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 */
859882void
860883init_deactivated_queries_storage (void )