@@ -176,32 +176,44 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
176
176
break ;
177
177
178
178
case T_ModifyTable :
179
+ oids = piggyback -> tableOids ;
179
180
result = (PlanState * ) ExecInitModifyTable ((ModifyTable * ) node , estate ,
180
181
eflags );
182
+ InvalidateStatisticsForTables (oids );
181
183
break ;
182
184
183
185
case T_Append :
186
+ oids = piggyback -> tableOids ;
184
187
result = (PlanState * ) ExecInitAppend ((Append * ) node , estate , eflags );
188
+ InvalidateStatisticsForTables (oids );
185
189
break ;
186
190
187
191
case T_MergeAppend :
192
+ oids = piggyback -> tableOids ;
188
193
result = (PlanState * ) ExecInitMergeAppend ((MergeAppend * ) node , estate ,
189
194
eflags );
195
+ InvalidateStatisticsForTables (oids );
190
196
break ;
191
197
192
198
case T_RecursiveUnion :
199
+ oids = piggyback -> tableOids ;
193
200
result = (PlanState * ) ExecInitRecursiveUnion ((RecursiveUnion * ) node ,
194
201
estate , eflags );
202
+ InvalidateStatisticsForTables (oids );
195
203
break ;
196
204
197
205
case T_BitmapAnd :
206
+ oids = piggyback -> tableOids ;
198
207
result = (PlanState * ) ExecInitBitmapAnd ((BitmapAnd * ) node , estate ,
199
208
eflags );
209
+ InvalidateStatisticsForTables (oids );
200
210
break ;
201
211
202
212
case T_BitmapOr :
213
+ oids = piggyback -> tableOids ;
203
214
result = (PlanState * ) ExecInitBitmapOr ((BitmapOr * ) node , estate ,
204
215
eflags );
216
+ InvalidateStatisticsForTables (oids );
205
217
break ;
206
218
207
219
/*
@@ -354,12 +366,16 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
354
366
355
367
// we do not want to invalid the statistic values, because they do not change the values from the original tables
356
368
case T_Agg :
369
+ oids = piggyback -> tableOids ;
357
370
result = (PlanState * ) ExecInitAgg ((Agg * ) node , estate , eflags );
371
+ InvalidateStatisticsForTables (oids );
358
372
break ;
359
373
360
374
case T_WindowAgg :
375
+ oids = piggyback -> tableOids ;
361
376
result = (PlanState * ) ExecInitWindowAgg ((WindowAgg * ) node , estate ,
362
377
eflags );
378
+ InvalidateStatisticsForTables (oids );
363
379
break ;
364
380
365
381
case T_Unique :
@@ -380,7 +396,9 @@ ExecInitNode(Plan *node, EState *estate, int eflags) {
380
396
break ;
381
397
382
398
case T_Limit :
399
+ oids = piggyback -> tableOids ;
383
400
result = (PlanState * ) ExecInitLimit ((Limit * ) node , estate , eflags );
401
+ InvalidateStatisticsForTables (oids );
384
402
break ;
385
403
386
404
default :
@@ -416,11 +434,29 @@ void
416
434
InvalidateStatisticsForTables (List * oldTableOids )
417
435
{
418
436
List * relevantTableOids = NULL ;
419
- ListCell * l ;
420
- relevantTableOids = list_difference (piggyback -> tableOids , oldTableOids );
421
- foreach (l , relevantTableOids )
437
+ ListCell * l1 ;
438
+ ListCell * l2 ;
439
+ //relevantTableOids = list_difference(piggyback->tableOids, oldTableOids);
440
+ foreach (l1 , piggyback -> tableOids )
441
+ {
442
+ int isNewOid = 1 ;
443
+ foreach (l2 , oldTableOids )
444
+ {
445
+ if (* ((int * )lfirst (l1 )) == * ((int * )lfirst (l2 )))
446
+ {
447
+ isNewOid = 0 ;
448
+ break ;
449
+ }
450
+ }
451
+ if (isNewOid == 1 )
452
+ {
453
+ relevantTableOids = lappend (relevantTableOids , (int * )lfirst (l1 ));
454
+ }
455
+ }
456
+
457
+ foreach (l1 , relevantTableOids )
422
458
{
423
- int currentOid = * ((int * )lfirst (l ));
459
+ int currentOid = * ((int * )lfirst (l1 ));
424
460
InvalidateStatisticsForTable (currentOid );
425
461
}
426
462
}
@@ -530,6 +566,9 @@ LookForFilterWithEquality(PlanState* result, Oid tableOid, List* qual)
530
566
break ;
531
567
}
532
568
569
+ // invalid all columns of this table, because there is a selection
570
+ InvalidateStatisticsForTable (tableOid );
571
+
533
572
// the magic numbers are operator identifiers from posgres/src/include/catalog/pg_operator.h
534
573
// equals
535
574
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
@@ -590,7 +629,7 @@ LookForFilterWithEquality(PlanState* result, Oid tableOid, List* qual)
590
629
else {
591
630
printf ("this opno is no =, <, >, <= or >=: %d (for column id %d)\n" , opno , columnId );
592
631
// found a selection, therefore we cannot use old statistics
593
- InvalidateStatisticsForTable (tableOid );
632
+ // InvalidateStatisticsForTable(tableOid); (this has to be always, because there could be more than one column of this table in the result
594
633
}
595
634
}
596
635
}
0 commit comments