Skip to content

Commit 9c1bede

Browse files
a.pervushinadanolivo
a.pervushina
authored andcommitted
Reconcile backed (PG 15 -> 13) features with the code of PG13.
1 parent c387db7 commit 9c1bede

10 files changed

+29
-37
lines changed

‎aqo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ _PG_init(void)
247247
RegisterResourceReleaseCallback(aqo_free_callback, NULL);
248248
RegisterAQOPlanNodeMethods();
249249

250-
MarkGUCPrefixReserved("aqo");
250+
EmitWarningsOnPlaceholders("aqo");
251251
RequestAddinShmemSpace(aqo_memsize());
252252
}
253253

‎cardinality_estimation.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ predict_debug_output(List *clauses, List *selectivities,
4545
appendStringInfoString(&debug_str, "}, relnames: { ");
4646
foreach(lc, relnames)
4747
{
48-
String *relname = lfirst_node(String, lc);
49-
appendStringInfo(&debug_str, "%s ", relname->sval);
48+
Value *relname = lfirst_node(String, lc);
49+
appendStringInfo(&debug_str, "%s ", valStr(relname));
5050
}
5151

5252
appendStringInfo(&debug_str, "}, result: %lf", result);

‎cardinality_hooks.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,9 @@ aqo_set_baserel_rows_estimate(PlannerInfo *root, RelOptInfo *rel)
164164
rte = planner_rt_fetch(rel->relid, root);
165165
if (rte && OidIsValid(rte->relid))
166166
{
167-
String *s = makeNode(String);
168-
169167
/* Predict for a plane table. */
170168
Assert(rte->eref && rte->eref->aliasname);
171-
s->sval = pstrdup(rte->eref->aliasname);
172-
relnames = list_make1(s);
169+
relnames = list_make1(makeString(pstrdup(rte->eref->aliasname)));
173170
}
174171

175172
clauses = aqo_get_clauses(root, rel->baserestrictinfo);
@@ -276,12 +273,9 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
276273

277274
if (rte && OidIsValid(rte->relid))
278275
{
279-
String *s = makeNode(String);
280-
281276
/* Predict for a plane table. */
282277
Assert(rte->eref && rte->eref->aliasname);
283-
s->sval = pstrdup(rte->eref->aliasname);
284-
relnames = list_make1(s);
278+
relnames = list_make1(makeString(pstrdup(rte->eref->aliasname)));
285279
}
286280

287281
predicted = predict_for_relation(allclauses, selectivities, relnames, &fss);

‎expected/gucs.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF)
3434

3535
-- Check existence of the interface functions.
3636
SELECT obj_description('public.show_cardinality_errors'::regproc::oid);
37-
obj_description
37+
obj_description
3838
-----------------------------------------------------------------------------------------
3939
Get cardinality error of last query execution. Return queries having the largest error.
4040
(1 row)

‎expected/unsupported.out

+4-3
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ NOTICE: Cleaning aqo_data records
582582
-- TODO: figure out with remaining queries in the ML storage.
583583
SELECT num, to_char(error, '9.99EEEE')::text AS error, query_text
584584
FROM public.show_cardinality_errors() cef, aqo_query_texts aqt
585-
WHERE aqt.query_hash = cef.id;
585+
WHERE aqt.query_hash = cef.id
586+
ORDER BY (error, md5(query_text)) DESC;
586587
num | error | query_text
587588
-----+-----------+-------------------------------------------------------------------------------------------
588589
1 | 9.69e+02 | SELECT str FROM expln(' +
@@ -598,9 +599,9 @@ WHERE aqt.query_hash = cef.id;
598599
| | to_char(error, '9.99EEEE')::text AS error +
599600
| | FROM public.show_cardinality_errors() +
600601
| | WHERE error > 0.;
601-
3 | 0.00e+00 | CREATE TABLE t AS SELECT (gs.* / 50) AS x FROM generate_series(1,1000) AS gs;
602+
5 | 0.00e+00 | CREATE TABLE t AS SELECT (gs.* / 50) AS x FROM generate_series(1,1000) AS gs;
602603
4 | 0.00e+00 | SELECT public.clean_aqo_data();
603-
5 | 0.00e+00 | CREATE TABLE t1 AS SELECT mod(gs,10) AS x, mod(gs+1,10) AS y +
604+
3 | 0.00e+00 | CREATE TABLE t1 AS SELECT mod(gs,10) AS x, mod(gs+1,10) AS y +
604605
| | FROM generate_series(1,1000) AS gs;
605606
(5 rows)
606607

‎hash.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,11 @@ get_relations_hash(List *relnames)
449449
/* generate array of hashes. */
450450
foreach(lc, relnames)
451451
{
452-
String *relname = lfirst_node(String, lc);
452+
Value *relname = (Value *) lfirst(lc);
453453

454454
hashes[i++] = DatumGetInt64(hash_any_extended(
455-
(unsigned char *) relname->sval,
456-
strlen(relname->sval), 0));
455+
(unsigned char *) strVal(relname),
456+
strlen(strVal(relname)), 0));
457457
}
458458

459459
/* Sort the array to make query insensitive to input order of relations. */

‎learn_cache.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ calculate_size(int cols, List *relnames)
5656
/* Calculate memory size needed to store relation names */
5757
foreach(lc, relnames)
5858
{
59-
size += strlen(lfirst_node(String, lc)->sval) + 1;
59+
size += strlen(strVal(lfirst(lc))) + 1;
6060
}
6161

6262
return size;
@@ -134,7 +134,7 @@ lc_update_fss(uint64 fs, int fss, OkNNrdata *data, List *relnames)
134134
/* store strings of relation names. Each string ends with 0-byte */
135135
foreach(lc, relnames)
136136
{
137-
char *relname = lfirst_node(String, lc)->sval;
137+
char *relname = strVal(lfirst(lc));
138138
int len = strlen(relname) + 1;
139139

140140
memcpy(ptr, relname, len);
@@ -245,11 +245,9 @@ init_with_dsm(OkNNrdata *data, dsm_block_hdr *hdr, List **relnames)
245245
*relnames = NIL;
246246
for (i = 0; i < hdr->nrelids; i++)
247247
{
248-
String *s = makeNode(String);
249248
int len = strlen(ptr) + 1;
250249

251-
s->sval = pstrdup(ptr);
252-
*relnames = lappend(*relnames, s);
250+
*relnames = lappend(*relnames, makeString(pstrdup(ptr)));
253251
ptr += len;
254252
}
255253
return calculate_size(hdr->cols, *relnames);

‎path_utils.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,7 @@ get_relnames(PlannerInfo *root, Relids relids)
148148
{
149149
rte = planner_rt_fetch(i, root);
150150
if (OidIsValid(rte->relid))
151-
{
152-
String *s = makeNode(String);
153-
154-
s->sval = pstrdup(rte->eref->aliasname);
155-
l = lappend(l, s);
156-
}
151+
l = lappend(l, makeString(pstrdup(rte->eref->aliasname)));
157152
}
158153
return l;
159154
}
@@ -648,9 +643,9 @@ aqo_store_upper_signature_hook(PlannerInfo *root,
648643
set_cheapest(input_rel);
649644
clauses = get_path_clauses(input_rel->cheapest_total_path,
650645
root, &selectivities);
651-
relids = get_list_of_relids(root, input_rel->relids);
646+
relnames = get_relnames(root, input_rel->relids);
652647
fss_node->val.type = T_Integer;
653648
fss_node->location = -1;
654-
fss_node->val.val.ival = get_fss_for_object(relids, clauses, NIL, NULL, NULL);
649+
fss_node->val.val.ival = get_fss_for_object(relnames, clauses, NIL, NULL, NULL);
655650
output_rel->ext_nodes = lappend(output_rel->ext_nodes, (void *) fss_node);
656651
}

‎sql/unsupported.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ SELECT public.clean_aqo_data();
187187
-- TODO: figure out with remaining queries in the ML storage.
188188
SELECT num, to_char(error, '9.99EEEE')::text AS error, query_text
189189
FROM public.show_cardinality_errors() cef, aqo_query_texts aqt
190-
WHERE aqt.query_hash = cef.id;
190+
WHERE aqt.query_hash = cef.id
191+
ORDER BY (error, md5(query_text)) DESC;
191192

192193
DROP EXTENSION aqo;

‎storage.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include "postgres.h"
1919

20+
#include "nodes/value.h"
21+
#include "postgres.h"
22+
2023
#include "access/heapam.h"
2124
#include "access/table.h"
2225
#include "access/tableam.h"
@@ -336,7 +339,7 @@ form_strings_vector(List *relnames)
336339

337340
foreach(lc, relnames)
338341
{
339-
char *relname = (lfirst_node(String, lc))->sval;
342+
char *relname = strVal(lfirst(lc));
340343

341344
rels[i++] = CStringGetTextDatum(relname);
342345
}
@@ -359,9 +362,9 @@ deform_strings_vector(Datum datum)
359362
&values, NULL, &nelems);
360363
for (i = 0; i < nelems; ++i)
361364
{
362-
String *s = makeNode(String);
365+
Value *s;
363366

364-
s->sval = pstrdup(TextDatumGetCString(values[i]));
367+
s = makeString(pstrdup(TextDatumGetCString(values[i])));
365368
relnames = lappend(relnames, s);
366369
}
367370

@@ -448,7 +451,7 @@ load_fss(uint64 fs, int fss, OkNNrdata *data, List **relnames)
448451
elog(ERROR, "unexpected number of features for hash (" \
449452
UINT64_FORMAT", %d):\
450453
expected %d features, obtained %d",
451-
fs, fss, ncols, DatumGetInt32(values[2]));
454+
fs, fss, data->cols, DatumGetInt32(values[2]));
452455
}
453456
else
454457
success = false;
@@ -583,7 +586,7 @@ update_fss(uint64 fs, int fss, OkNNrdata *data, List *relnames)
583586
*/
584587
elog(ERROR, "AQO data piece ("UINT64_FORMAT" %d) concurrently"
585588
" updated by a stranger backend.",
586-
fhash, fsshash);
589+
fs, fss);
587590
result = false;
588591
}
589592
}

0 commit comments

Comments
 (0)