diff --git a/_FiveSql2/src/TSqlExecutor.prg b/_FiveSql2/src/TSqlExecutor.prg index be0c090..1f0b7d8 100644 --- a/_FiveSql2/src/TSqlExecutor.prg +++ b/_FiveSql2/src/TSqlExecutor.prg @@ -18,6 +18,11 @@ STATIC s_aOuterStack := {} STATIC s_hAutoInc := NIL STATIC s_nRCJSeq := 0 +/* Set .T. the first time CTE cleanup sees a legacy __cte_.dbf + * file on disk, or the legacy DBFNTX open path fires. Profile showed + * the stat loop at ~20% of total CPU otherwise — MEMRDD is the norm + * for CTEs so the .dbf doesn't exist and the stat is pure overhead. */ +STATIC s_lCteDiskSeen := .F. /* Per-plan DML pcode cache. Keyed by the plan-cache key that TFiveSQL * uses (template key or cSQL text); value is a hash: @@ -1245,6 +1250,7 @@ METHOD RunSelect() CLASS TSqlExecutor nWA := 0 END SEQUENCE IF nWA == 0 .AND. hb_FileExists( "__cte_" + Lower( cTable ) + ".dbf" ) + s_lCteDiskSeen := .T. BEGIN SEQUENCE dbUseArea( .T., "DBFNTX", "__cte_" + Lower( cTable ) + ".dbf", ; cAlias, .T., .T. ) @@ -1640,9 +1646,14 @@ METHOD RunSelect() CLASS TSqlExecutor dbSelectArea( nWA ) dbCloseArea() ENDIF - cTable := "__cte_" + Lower( ::hQuery[ "cte" ][ i ][ 1 ] ) - IF hb_FileExists( cTable + ".dbf" ) - FErase( cTable + ".dbf" ) + /* Legacy disk fallback cleanup — only runs when a __cte_*.dbf + * has actually been seen (either from a prior crash or a + * MEMRDD-failure legacy open). MEMRDD-only runs skip the stat. */ + IF s_lCteDiskSeen + cTable := "__cte_" + Lower( ::hQuery[ "cte" ][ i ][ 1 ] ) + IF hb_FileExists( cTable + ".dbf" ) + FErase( cTable + ".dbf" ) + ENDIF ENDIF NEXT ENDIF