TSqlExecutor:OpenTable now hands lifetime to the WA cache for stable aliases (user-supplied or table-named). CloseOpened skips those entries, so the DBF mmap stays alive across queries instead of being unmapped + re-opened 1000 times a bench. Previously the WA cache only covered DML (INSERT/UPDATE/DELETE) — SELECT was still paying the full dbUseArea/dbCloseArea syscall bill every query (profile showed rtlDbCloseArea + munmap at ~30% of total CPU). AcquireTemp-generated aliases (FA_####) are excluded — they change every query (self-joins, nested depth), so caching them would just leak entries for no reuse. JOIN / recursive CTE regressions from an earlier unrestricted version are gone. Bench deltas vs prior HEAD (median of 3 steady runs, 1000 iters): B1_SELECT_STAR 82 → 41 us -50% (2.0x) B2_WHERE_FILTER 78 → 35 us -55% (2.2x) B3_ORDER_BY 90 → 48 us -47% (1.88x) B5_DISTINCT 75 → 32 us -57% (2.34x) B7_CTE_SIMPLE 120 → 77 us -36% (1.56x) B9_ROW_NUMBER 239 → 194 us -19% B10_RANK_PART 276 → 233 us -16% B11_SUM_OVER 296 → 252 us -15% B4_GROUP_HAVING 498 → 450 us -10% Others flat (JOIN / recursive CTE / DML already covered). FiveSql2 43/43, Harbour compat 56/56. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
FiveSql2 — SQL Engine for Harbour DBF/NTX/CDX
Pratt parser + SQL:1992-2023 full standard support Supports both NTX (Clipper) and CDX (FoxPro/ADS) indexes
Architecture
five_SQL("SELECT ...")
│
├── TSqlLexer Tokenizer
├── TSqlParser2 Pratt parser (data-driven operators)
├── TSqlExecutor Query executor (Volcano model)
│ ├── TSqlAlias Central alias manager (no collisions)
│ ├── TSqlIndex NTX/CDX index optimization (auto-detect)
│ ├── TSqlAgg GROUP BY / aggregation
│ ├── TSqlSort ORDER BY / DISTINCT
│ ├── TSqlDDL CREATE/DROP/ALTER TABLE/INDEX
│ └── TSqlTxn BEGIN/COMMIT/ROLLBACK
├── TSqlExpr AST nodes + expression evaluation
└── TSqlFunc 60+ scalar functions
Build & Test
export PATH="/path/to/harbour-core/bin/linux/gcc:$PATH"
export HB_INSTALL_PREFIX="/path/to/harbour-core"
make # Build all tests
make test # Run all 157 tests
make bench # Parser benchmark
make clean # Clean
SQL Standard Coverage
| Standard | Features | Tests |
|---|---|---|
| SQL:1992 | SELECT, JOIN, GROUP BY, HAVING, Subquery, CASE, CAST | 43 |
| SQL:1999 | CTE, Recursive CTE, Window Functions, MERGE | 10 |
| SQL:2003 | SIMILAR TO, GROUPING SETS, LATERAL, Window frames | 64 |
| SQL:2008 | FETCH/OFFSET, FOR UPDATE, Extended MERGE | (incl.) |
| SQL:2016 | JSON functions, LISTAGG | (incl.) |
| SQL:2023 | ANY_VALUE, GREATEST/LEAST, BOOL_AND/OR | (incl.) |
| Challenge | LeetCode-level complex queries | 15 |
| Extreme | Production analytics stress tests | 15 |
Adding New Operators
Edit TSqlParser2.prg, method InitInfixTables():
::hInfixTT[ TK_MYOP ] := { "<=>", 40, 41, ND_BIN }
One line. No structural changes needed.
Copyright
Copyright (c) 2025-2026 Charles KWON (Charles KWON OhJun) Email: charleskwonohjun@gmail.com All rights reserved.