diff --git a/_FiveSql2/src/TSqlExecutor.prg b/_FiveSql2/src/TSqlExecutor.prg index a164be6..0431f7d 100644 --- a/_FiveSql2/src/TSqlExecutor.prg +++ b/_FiveSql2/src/TSqlExecutor.prg @@ -202,7 +202,18 @@ METHOD OpenTable( cTable, cAlias ) CLASS TSqlExecutor nWA := ::oIndex:OpenTable( cTable, cAlias, .T., .T. ) IF nWA > 0 - AAdd( ::aOpened, cAlias ) + /* When the WA cache is on, hand lifetime to the cache so CloseOpened + * leaves the mmap alive for the next query. Profile showed + * rtlDbCloseArea + munmap at ~30% of SELECT CPU prior to this branch. + * + * Skip caching when the alias is an AcquireTemp-generated "FA_####" + * token: those change every query (self-joins, nested depth), so + * caching them just leaks entries while delivering zero reuse. */ + IF SqlWACacheIsEnabled() .AND. ! ( Left( cAlias, 3 ) == "FA_" ) + SqlWACachePut( cAlias, nWA ) + ELSE + AAdd( ::aOpened, cAlias ) + ENDIF /* Register with alias manager if not already tracked */ lFound := .F. FOR i := 1 TO Len( ::oAlias:aSlots )