8000 Add AQO_DEBUG_PRINT parameter to add many additional printing to debug · postgrespro/aqo@5c9b0b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c9b0b3

Browse files
committed
Add AQO_DEBUG_PRINT parameter to add many additional printing to debug
learning machinery. Add missed nodes into the get_path_clauses() routine. Introduce 'Appropriate path' concept to avoid duplication of the same clauses at learning phase. TODO: This concept should be rethink.
1 parent 60bd5e0 commit 5c9b0b3

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

cardinality_estimation.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,37 @@
2222
#include "aqo.h"
2323
#include "hash.h"
2424

25+
#ifdef AQO_DEBUG_PRINT
26+
static void
27+
predict_debug_output(List *clauses, List *selectivities,
28+
List *relids, int fss_hash, double result)
29+
{
30+
StringInfoData debug_str;
31+
ListCell *lc;
32+
33+
initStringInfo(&debug_str);
34+
appendStringInfo(&debug_str, "fss: %d, clausesNum: %d, ",
35+
fss_hash, list_length(clauses));
36+
37+
appendStringInfoString(&debug_str, ", selectivities: { ");
38+
foreach(lc, selectivities)
39+
{
40+
Selectivity *s = (Selectivity *) lfirst(lc);
41+
appendStringInfo(&debug_str, "%lf ", *s);
42+
}
43+
44+
appendStringInfoString(&debug_str, "}, relids: { ");
45+
foreach(lc, relids)
46+
{
47+
int relid = lfirst_int(lc);
48+
appendStringInfo(&debug_str, "%d ", relid);
49+
}
50+
51+
appendStringInfo(&debug_str, "}, result: %lf", result);
52+
elog(DEBUG1, "Prediction: %s", debug_str.data);
53+
pfree(debug_str.data);
54+
}
55+
#endif
2556

2657
/*
2758
* General method for prediction the cardinality of given relation.
@@ -65,7 +96,9 @@ predict_for_relation(List *clauses, List *selectivities,
6596
*/
6697
result = -1;
6798
}
68-
99+
#ifdef AQO_DEBUG_PRINT
100+
predict_debug_output(clauses, selectivities, relids, *fss_hash, result);
101+
#endif
69102
pfree(features);
70103
if (nfeatures > 0)
71104
{

path_utils.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,29 @@ get_path_clauses(Path *path, PlannerInfo *root, List **selectivities)
258258
return get_path_clauses(((MaterialPath *) path)->subpath, root,
259259
selectivities);
260260
break;
261+
case T_MemoizePath:
262+
return get_path_clauses(((MemoizePath *) path)->subpath, root,
263+
selectivities);
264+
break;
261265
case T_ProjectionPath:
262266
return get_path_clauses(((ProjectionPath *) path)->subpath, root,
263267
selectivities);
264268
break;
269+
case T_ProjectSetPath:
270+
return get_path_clauses(((ProjectSetPath *) path)->subpath, root,
271+
selectivities);
272+
break;
265273
case T_SortPath:
266274
return get_path_clauses(((SortPath *) path)->subpath, root,
267275
selectivities);
268276
break;
277+
case T_IncrementalSortPath:
278+
{
279+
IncrementalSortPath *p = (IncrementalSortPath *) path;
280+
return get_path_clauses(p->spath.subpath, root,
281+
selectivities);
282+
}
283+
break;
269284
case T_GroupPath:
270285
return get_path_clauses(((GroupPath *) path)->subpath, root,
271286
selectivities);
@@ -302,10 +317,20 @@ get_path_clauses(Path *path, PlannerInfo *root, List **selectivities)
302317
return get_path_clauses(((SubqueryScanPath *) path)->subpath, root,
303318
selectivities);
304319
break;
320+
case T_ModifyTablePath:
321+
return get_path_clauses(((ModifyTablePath *) path)->subpath, root,
322+
selectivities);
323+
break;
324+
/* TODO: RecursiveUnionPath */
305325
case T_AppendPath:
326+
case T_MergeAppendPath:
306327
{
307328
ListCell *lc;
308329

330+
/*
331+
* It isn't a safe style, but we use the only subpaths field that is
332+
* the first at both Append and MergeAppend nodes.
333+
*/
309334
foreach (lc, ((AppendPath *) path)->subpaths)
310335
{
311336
Path *subpath = lfirst(lc);
@@ -343,6 +368,33 @@ get_path_clauses(Path *path, PlannerInfo *root, List **selectivities)
343368
}
344369
}
345370

371+
/*
372+
* Some of paths are kind of utility path. I mean, It isn't corresponding to
373+
* specific RelOptInfo node. So, it should be omitted in process of clauses
374+
* gathering to avoid duplication of the same clauses.
375+
* XXX: only a dump plug implemented for now.
376+
*/
377+
static bool
378+
is_appropriate_path(Path *path)
379+
{
380+
bool appropriate = true;
381+
382+
switch (path->type)
383+
{
384+
case T_SortPath:
385+
case T_IncrementalSortPath:
386+
case T_MemoizePath:
387+
case T_GatherPath:
388+
case T_GatherMergePath:
389+
appropriate = false;
390+
break;
391+
default:
392+
break;
393+
}
394+
395+
return appropriate;
396+
}
397+
346398
/*
347399
* Converts path info into plan node for collecting it after query execution.
348400
*/
@@ -392,7 +444,7 @@ aqo_create_plan_hook(PlannerInfo *root, Path *src, Plan **dest)
392444
node->relids = get_list_of_relids(root, ap->subpath->parent->relids);
393445
node->jointype = JOIN_INNER;
394446
}
395-
else
447+
else if (is_appropriate_path(src))
396448
{
397449
node->clauses = list_concat(
398450
aqo_get_clauses(root, src->parent->baserestrictinfo),

0 commit comments

Comments
 (0)
0