@@ -336,17 +336,53 @@ should_learn(PlanState *ps, AQOPlanNode *node, aqo_obj_stat *ctx,
336
336
}
337
337
else if (ctx -> learn )
338
338
{
339
- elog (NOTICE , "fss %d, IsNull %s, nloops %lf" , node -> fss , TupIsNull (ps -> ps_ResultTupleSlot ) ? "true" : "false" , ps -> instrument -> nloops );
340
- if ( IsA (ps , HashJoinState ))
339
+ // elog(NOTICE, "fss %d, IsNull %s, nloops %lf", node->fss, TupIsNull(ps->ps_ResultTupleSlot) ? "true" : "false", ps->instrument->nloops);
340
+ switch ( nodeTag (ps ))
341
341
{
342
- HashJoinState * hjstate = castNode (HashJoinState , ps );
343
- elog (NOTICE , "TerminatedEarly %s" , hjstate -> hj_TerminatedEarly ? "true" : "false" );
344
- if (hjstate -> hj_TerminatedEarly )
342
+ case T_SeqScanState :
343
+ case T_SampleScanState :
344
+ case T_IndexScanState :
345
+ case T_IndexOnlyScanState :
346
+ case T_BitmapHeapScanState :
347
+ case T_TidScanState :
348
+ case T_TidRangeScanState :
349
+ case T_ForeignScanState :
350
+ case T_CustomScanState :
345
351
{
346
- * rfactor = RELIABILITY_MIN ;
347
- return true;
352
+ ScanState * sstate = (ScanState * ) ps ;
353
+
354
+ if (!TupIsNull (sstate -> ss_ScanTupleSlot ) && ps -> instrument -> nloops > 0. )
355
+ {
356
+ /* If the scan node was terminated early, skip it*/
357
+ elog (NOTICE , "ScanState terminated early" );
358
+ return false;
359
+ }
360
+ //elog(NOTICE, "ScanState, isnull ss_ScanTupleSlot %s", TupIsNull(sstate->ss_ScanTupleSlot) ? "true" : "false");
361
+ break ;
362
+ }
363
+ case T_HashJoinState :
364
+ {
365
+ HashJoinState * hjstate ;
366
+ ScanState * sstate ;
367
+ PlanState * outerNode ;
368
+
369
+ hjstate = castNode (HashJoinState , ps );
370
+ outerNode = outerPlanState (hjstate );
371
+ sstate = (ScanState * ) outerNode ;
372
+
373
+ if (!TupIsNull (sstate -> ss_ScanTupleSlot ) && outerNode -> instrument -> nloops > 0. )
374
+ {
375
+ /* If the scan node was terminated early, lower reliability for HashJoin node*/
376
+ elog (NOTICE , "HashJoin ScanState terminated early" );
377
+ * rfactor = 0.9 * (RELIABILITY_MAX - RELIABILITY_MIN );
378
+ return true;
379
+ }
380
+ break ;
348
381
}
382
+ default :
383
+ break ;
349
384
}
385
+
350
386
* rfactor = RELIABILITY_MAX ;
351
387
return true;
352
388
}
0 commit comments