@@ -130,7 +130,8 @@ extern Piggyback *piggyback;
130
130
void fillFDCandidateMaps ();
131
131
void addToTwoColumnCombinationHashSet (int from , char * valueToConcat , int to , char * value );
132
132
void LookForFilterWithEquality (PlanState * result , Oid tableOid , List * qual );
133
-
133
+ void InvalidateStatisticsForTables (List * oldTableOids );
134
+ void InvalidateStatisticsForTable (int tableOid );
134
135
/* ------------------------------------------------------------------------
135
136
* ExecInitNode
136
137
*
@@ -155,6 +156,7 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
155
156
SeqScanState * resultAsScanState ;
156
157
IndexScanState * resultAsIndexScan ;
157
158
IndexOnlyScanState * resultAsIndexOnlyScan ;
159
+ List * oids = NULL ;
158
160
int tableOid = -1 ;
159
161
/*
160
162
* do nothing when we get to the end of a leaf on tree.
@@ -214,7 +216,10 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
214
216
215
217
if (tableOid != -1 && piggyback != NULL )
216
218
{
219
+ int * tableOidPtr = (int * ) malloc (sizeof (int ));
220
+ * tableOidPtr = tableOid ;
217
221
LookForFilterWithEquality (result , tableOid , result -> qual );
222
+ piggyback -> tableOids = lappend (piggyback -> tableOids , tableOidPtr );
218
223
}
219
224
break ;
220
225
@@ -230,7 +235,10 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
230
235
231
236
if (tableOid != -1 )
232
237
{
238
+ int * tableOidPtr = (int * ) malloc (sizeof (int ));
239
+ * tableOidPtr = tableOid ;
233
240
LookForFilterWithEquality (result , tableOid , resultAsIndexScan -> indexqualorig );
241
+ piggyback -> tableOids = lappend (piggyback -> tableOids , tableOidPtr );
234
242
}
235
243
break ;
236
244
@@ -247,71 +255,89 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
247
255
248
256
if (tableOid != -1 )
249
257
{
258
+ int * tableOidPtr = (int * ) malloc (sizeof (int ));
259
+ * tableOidPtr = tableOid ;
250
260
LookForFilterWithEquality (result , tableOid , resultAsIndexOnlyScan -> indexqual );
261
+ piggyback -> tableOids = lappend (piggyback -> tableOids , tableOidPtr );
251
262
}
252
263
break ;
253
264
254
265
case T_BitmapIndexScan :
255
266
result = (PlanState * ) ExecInitBitmapIndexScan ((BitmapIndexScan * ) node ,
256
267
estate , eflags );
268
+ printf (" Bitmap " );
257
269
break ;
258
270
259
271
case T_BitmapHeapScan :
260
272
result = (PlanState * ) ExecInitBitmapHeapScan ((BitmapHeapScan * ) node ,
261
273
estate , eflags );
274
+ printf (" BitmapHeap " );
262
275
break ;
263
276
264
277
case T_TidScan :
265
278
result = (PlanState * ) ExecInitTidScan ((TidScan * ) node , estate ,
266
279
eflags );
280
+ printf (" Tid " );
267
281
break ;
268
282
269
283
case T_SubqueryScan :
270
284
result = (PlanState * ) ExecInitSubqueryScan ((SubqueryScan * ) node ,
271
285
estate , eflags );
286
+ printf (" Subquery " );
272
287
break ;
273
288
274
289
case T_FunctionScan :
275
290
result = (PlanState * ) ExecInitFunctionScan ((FunctionScan * ) node ,
276
291
estate , eflags );
292
+ printf (" Function " );
277
293
break ;
278
294
279
295
case T_ValuesScan :
280
296
result = (PlanState * ) ExecInitValuesScan ((ValuesScan * ) node , estate ,
281
297
eflags );
298
+ printf (" Values " );
282
299
break ;
283
300
284
301
case T_CteScan :
285
302
result = (PlanState * ) ExecInitCteScan ((CteScan * ) node , estate ,
286
303
eflags );
304
+ printf (" Cte " );
287
305
break ;
288
306
289
307
case T_WorkTableScan :
290
308
result = (PlanState * ) ExecInitWorkTableScan ((WorkTableScan * ) node ,
291
309
estate , eflags );
310
+ printf (" WorkTable " );
292
311
break ;
293
312
294
313
case T_ForeignScan :
295
314
result = (PlanState * ) ExecInitForeignScan ((ForeignScan * ) node , estate ,
296
315
eflags );
316
+ printf (" Foreign " );
297
317
break ;
298
318
299
319
/*
300
320
* join nodes
301
321
*/
302
322
case T_NestLoop :
323
+ oids = piggyback -> tableOids ;
303
324
result = (PlanState * ) ExecInitNestLoop ((NestLoop * ) node , estate ,
304
325
eflags );
326
+ InvalidateStatisticsForTables (oids );
305
327
break ;
306
328
307
329
case T_MergeJoin :
330
+ oids = piggyback -> tableOids ;
308
331
result = (PlanState * ) ExecInitMergeJoin ((MergeJoin * ) node , estate ,
309
332
eflags );
333
+ InvalidateStatisticsForTables (oids );
310
334
break ;
311
335
312
336
case T_HashJoin :
337
+ oids = piggyback -> tableOids ;
313
338
result = (PlanState * ) ExecInitHashJoin ((HashJoin * ) node , estate ,
314
- eflags );
339
+ eflags );
340
+ InvalidateStatisticsForTables (oids );
315
341
break ;
316
342
317
343
/*
@@ -327,11 +353,14 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
327
353
break ;
328
354
329
355
case T_Group :
356
+ oids = piggyback -> tableOids ;
330
357
result = (PlanState * ) ExecInitGroup ((Group * ) node , estate , eflags );
358
+ InvalidateStatisticsForTables (oids );
331
359
break ;
332
360
361
+ // we do not want to invalid the statistic values, because they do not change the values from the original tables
333
362
case T_Agg :
334
- result = ExecInitAgg ((Agg * ) node , estate , eflags );
363
+ result = ( PlanState * ) ExecInitAgg ((Agg * ) node , estate , eflags );
335
364
break ;
336
365
337
366
case T_WindowAgg :
@@ -389,6 +418,36 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
389
418
return result ;
390
419
}
391
420
421
+ void
422
+ InvalidateStatisticsForTables (List * oldTableOids )
423
+ {
424
+ List * relevantTableOids = NULL ;
425
+ ListCell * l ;
426
+ relevantTableOids = list_difference (piggyback -> tableOids , oldTableOids );
427
+ foreach (l , relevantTableOids )
428
+ {
429
+ int currentOid = * ((int * )lfirst (l ));
430
+ InvalidateStatisticsForTable (currentOid );
431
+ }
432
+ }
433
+
434
+ void
435
+ InvalidateStatisticsForTable (int tableOid )
436
+ {
437
+ int i = 0 ;
438
+ for (; i < piggyback -> numberOfAttributes ; i ++ )
439
+ {
440
+ if (tableOid == piggyback -> resultStatistics -> columnStatistics [i ].columnDescriptor -> srctableid )
441
+ {
442
+ // this columnStatistic is obsolete
443
+ piggyback -> resultStatistics -> columnStatistics [i ].n_distinctIsFinal = 0 ;
444
+ piggyback -> resultStatistics -> columnStatistics [i ].minValueIsFinal = 0 ;
445
+ piggyback -> resultStatistics -> columnStatistics [i ].maxValueIsFinal = 0 ;
446
+ piggyback -> resultStatistics -> columnStatistics [i ].mostFrequentValueIsFinal = 0 ;
447
+ }
448
+ }
449
+ }
450
+
392
451
void
393
452
LookForFilterWithEquality (PlanState * result , Oid tableOid , List * qual )
394
453
{
@@ -407,8 +466,6 @@ LookForFilterWithEquality(PlanState* result, Oid tableOid, List* qual)
407
466
break ;
408
467
}
409
468
410
- // TODO: if (i < piggyback->numberOfAttributes) set useBaseStatistics to false
411
-
412
469
if (opno == 94 || opno == 96 || opno == 410 || opno == 416 || opno == 1862 || opno == 1868 || opno == 15 || opno == 532 || opno == 533 ) { // it is a equality like number_of_tracks = 3
413
470
int numberOfAttributes = result -> plan -> targetlist -> length ;
414
471
@@ -439,6 +496,11 @@ LookForFilterWithEquality(PlanState* result, Oid tableOid, List* qual)
439
496
printf ("there are statistics results from the selection that are not part of the result table\n" );
440
497
}
441
498
}
499
+ else {
500
+ printf ("this opno is no equality: %d (for column id %d)\n" , opno , columnId );
501
+ // found a selection, therefore we cannot use old statistics
502
+ InvalidateStatisticsForTable (tableOid );
503
+ }
442
504
}
443
505
}
444
506
0 commit comments