diff --git a/_FiveSql2/src/TSqlExecutor.prg b/_FiveSql2/src/TSqlExecutor.prg index 0431f7d..163109b 100644 --- a/_FiveSql2/src/TSqlExecutor.prg +++ b/_FiveSql2/src/TSqlExecutor.prg @@ -1662,12 +1662,17 @@ METHOD RunSelect() CLASS TSqlExecutor ENDIF /* Clean up VIEW temp files — created by TSqlIndex:CheckView when - * a query references a .fsv view. Not tracked elsewhere. */ - FOR i := 1 TO Len( ::aTables ) - IF hb_FileExists( "__view_" + Lower( ::aTables[ i ][ 1 ] ) + ".dbf" ) - FErase( "__view_" + Lower( ::aTables[ i ][ 1 ] ) + ".dbf" ) - ENDIF - NEXT + * a query references a .fsv view. The flag lets us skip the stat + * loop on view-free queries, which the profile showed as ~28% of + * SELECT CPU after the WA cache killed the munmap cost. */ + IF ::oIndex:lViewUsed + FOR i := 1 TO Len( ::aTables ) + IF hb_FileExists( "__view_" + Lower( ::aTables[ i ][ 1 ] ) + ".dbf" ) + FErase( "__view_" + Lower( ::aTables[ i ][ 1 ] ) + ".dbf" ) + ENDIF + NEXT + ::oIndex:lViewUsed := .F. + ENDIF ::nDepth-- diff --git a/_FiveSql2/src/TSqlIndex.prg b/_FiveSql2/src/TSqlIndex.prg index 257576d..c83556b 100644 --- a/_FiveSql2/src/TSqlIndex.prg +++ b/_FiveSql2/src/TSqlIndex.prg @@ -16,6 +16,11 @@ CLASS TSqlIndex + /* Set to .T. when CheckView materialises a __view_* temp for a + * table this query references — lets RunSelect skip its stat+ + * FErase cleanup loop on view-free queries (the common case). */ + DATA lViewUsed INIT .F. + METHOD New() CONSTRUCTOR METHOD DetectRDD( nWA ) METHOD OpenTable( cTable, cAlias, lShared, lReadOnly ) @@ -82,6 +87,7 @@ METHOD OpenTable( cTable, cAlias, lShared, lReadOnly ) CLASS TSqlIndex cViewTmp := ::CheckView( cTable ) IF ! Empty( cViewTmp ) cFileLow := cViewTmp + ::lViewUsed := .T. ENDIF ENDIF