8000 Reconcile backpatched (PG 15 -> 13) features with the code of PG13. · postgrespro/aqo@afd6e98 · GitHub
[go: up one dir, main page]

Skip to content

Commit afd6e98

Browse files
committed
Reconcile backpatched (PG 15 -> 13) features with the code of PG13.
1 parent 53e4f6b commit afd6e98

File tree

9 files changed

+28
-36
lines changed

9 files changed

+28
-36
lines changed

aqo.c

Lines changed: 1 addition & 1 deletion
}
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ _PG_init(void)
243243
RegisterResourceReleaseCallback(aqo_free_callback, NULL);
244244
RegisterAQOPlanNodeMethods();
245245

246-
MarkGUCPrefixReserved("aqo");
246+
EmitWarningsOnPlaceholders("aqo");
247247
RequestAddinShmemSpace(aqo_memsize());
248248
249249

cardinality_estimation.c

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 8 deletions
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);
@@ -269,12 +266,9 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
269266

270267
if (rte && OidIsValid(rte->relid))
271268
{
272-
String *s = makeNode(String);
273-
274269
/* Predict for a plane table. */
275270
Assert(rte->eref && rte->eref->aliasname);
276-
s->sval = pstrdup(rte->eref->aliasname);
277-
relnames = list_make1(s);
271+
relnames = list_make1(makeString(pstrdup(rte->eref->aliasname)));
278272
}
279273

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

expected/unsupported.out

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ NOTICE: Cleaning aqo_data records
566566
-- TODO: figure out with remaining queries in the ML storage.
567567
SELECT num, to_char(error, '9.99EEEE')::text AS error, query_text
568568
FROM public.show_cardinality_errors() cef, aqo_query_texts aqt
569-
WHERE aqt.query_hash = cef.id;
569+
WHERE aqt.query_hash = cef.id
570+
ORDER BY (error, md5(query_text)) DESC;
570571
num | error | query_text
571572
-----+-----------+-------------------------------------------------------------------------------------------
572573
1 | 9.69e+02 | SELECT str FROM expln(' +
@@ -582,9 +583,9 @@ WHERE aqt.query_hash = cef.id;
582583
| | to_char(error, '9.99EEEE')::text AS error +
583584
| | FROM public.show_cardinality_errors() +
584585
| | WHERE error > 0.;
585-
3 | 0.00e+00 | CREATE TABLE t AS SELECT (gs.* / 50) AS x FROM generate_series(1,1000) AS gs;
586+
5 | 0.00e+00 | CREATE TABLE t AS SELECT (gs.* / 50) AS x FROM generate_series(1,1000) AS gs;
586587
4 | 0.00e+00 | SELECT public.clean_aqo_data();
587-
5 | 0.00e+00 | CREATE TABLE t1 AS SELECT mod(gs,10) AS x, mod(gs+1,10) AS y +
588+
3 | 0.00e+00 | CREATE TABLE t1 AS SELECT mod(gs,10) AS x, mod(gs+1,10) AS y +
588589
| | FROM generate_series(1,1000) AS gs;
589590
(5 rows)
590591

hash.c

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 3 additions & 8 deletions
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
}
@@ -666,9 +661,9 @@ aqo_store_upper_signature_hook(PlannerInfo *root,
666661
set_cheapest(input_rel);
667662
clauses = get_path_clauses(input_rel->cheapest_total_path,
668663
root, &selectivities);
669-
relids = get_list_of_relids(root, input_rel->relids);
664+
relnames = get_relnames(root, input_rel->relids);
670665
fss_node->val.type = T_Integer;
671666
fss_node->location = -1;
672-
fss_node->val.val.ival = get_fss_for_object(relids, clauses, NIL, NULL, NULL);
667+
fss_node->val.val.ival = get_fss_for_object(relnames, clauses, NIL, NULL, NULL);
673668
output_rel->ext_nodes = lappend(output_rel->ext_nodes, (void *) fss_node);
674669
}

sql/unsupported.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ SELECT public.clean_aqo_data();
169169
-- TODO: figure out with remaining queries in the ML storage.
170170
SELECT num, to_char(error, '9.99EEEE')::text AS error, query_text
171171
FROM public.show_cardinality_errors() cef, aqo_query_texts aqt
172-
WHERE aqt.query_hash = cef.id;
172+
WHERE aqt.query_hash = cef.id
173+
ORDER BY (error, md5(query_text)) DESC;
173174

174175
DROP EXTENSION aqo;

storage.c

Lines changed: 8 additions & 5 deletions
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"
@@ -337,7 +340,7 @@ form_strings_vector(List *relnames)
337340

338341
foreach(lc, relnames)
339342
{
340-
char *relname = (lfirst_node(String, lc))->sval;
343+
char *relname = strVal(lfirst(lc));
341344

342345
rels[i++] = CStringGetTextDatum(relname);
343346
}
@@ -360,9 +363,9 @@ deform_strings_vector(Datum datum)
360363
&values, NULL, &nelems);
361364
for (i = 0; i < nelems; ++i)
362365
{
363-
String *s = makeNode(String);
366+
Value *s;
364367

365-
s->sval = pstrdup(TextDatumGetCString(values[i]));
368+
s = makeString(pstrdup(TextDatumGetCString(values[i])));
366369
relnames = lappend(relnames, s);
367370
}
368371

@@ -449,7 +452,7 @@ load_fss(uint64 fs, int fss, OkNNrdata *data, List **relnames)
449452
elog(ERROR, "unexpected number of features for hash (" \
450453
UINT64_FORMAT", %d):\
451454
expected %d features, obtained %d",
452-
fs, fss, ncols, DatumGetInt32(values[2]));
455+
fs, fss, data->cols, DatumGetInt32(values[2]));
453456
}
454457
else
455458
success = false;
@@ -584,7 +587,7 @@ update_fss(uint64 fs, int fss, OkNNrdata *data, List *relnames)
584587
*/
585588
elog(ERROR, "AQO data piece ("UINT64_FORMAT" %d) concurrently"
586589
" updated by a stranger backend.",
587-
fhash, fsshash);
590+
fs, fss);
588591
result = false;
589592
}
590593
}

0 commit comments

Comments
 (0)
0