Systematic pass through PRG hot paths, promoting them to Go RTL while
preserving Harbour/FiveSql2 semantics. Full log in
docs/RTL-Go-Native-Migration.md.
Bench (bench_sql) vs 2026-04-08 baseline
- B1 SELECT * 2,192 → 114 µs (19x)
- B6 INNER JOIN 9,291 → 233 µs (40x)
- B7 CTE simple 8,037 → 129 µs (62x)
- B9 ROW_NUMBER 3,705 → 265 µs (14x)
- B10 RANK PARTITION 4,748 → 309 µs (15x)
- B12 INSERT (WA cache) 4,319 → 63 µs (69x)
- B13 UPDATE (WA cache) 6,144 → 68 µs (90x)
- B15 CTE+WIN+JOIN 18,395 → 1,873 µs (10x)
Infrastructure
- HbHash O(1) Index preserving insertion order (Harbour KEEPORDER)
- HbDeepClone Go RTL (scalar-sharing, immutable hash keys)
- MEMRDD auto-imported via gengo; all Five programs get mem:name driver
- SQL plan + pcode caches (s_hPlanCache, s_hDmlPcodeCache)
- Opt-in SqlWACacheEnable — dbUseArea/Close/Commit batched for DML
SQL engine
- FiveSql2 lexer ported to Go (byte FSM) with combined automatic
template parameterization (literals → ?, concat queries share plan)
- Go RTL: SqlDistinct, SqlGroupRows, SqlWindowPartitions,
SqlWindowSortPartition, SqlWindowAssignRank, SqlComputeAggSimple,
SqlBulkInsert, SqlBulkUpdate, SqlExprHasAgg, SqlEvalHaving
- CTE / subquery / driving-table materialize paths use MEMRDD
- SqlCoerce/SqlCmp/SqlIsTrue helpers moved from PRG to Go
- SqlBulkUpdate defers Flush when WA cache active (APFS fsync was
dominant B13 cost — 1.6ms/call → gone)
Correctness fixes uncovered during migration
- ASort default path now sorts dates/logicals/timestamps (was no-op)
- ORDER BY default NULL placement matches PRG SqlRowCompare across
Go fast path; explicit NULLS FIRST/LAST honored by both paths
- SqlBulkUpdate respects EXCLUSIVE vs SHARED mode record locks
- SqlCmp/SqlCmpEq normalize NumInt vs Double (caught by test 6b)
Verification
- go test ./... ALL PASS
- FiveSql2 test_sql1999 43/43
- tests/compat_harbour 56/56 (+5 new: ASort dates/logicals,
AScan int cross-type)
- Regression test test_null_order.prg for ORDER BY NULL ordering
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
106 lines
2.3 KiB
Go
106 lines
2.3 KiB
Go
// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
|
|
// All rights reserved.
|
|
|
|
// Hash functions for the Five runtime library.
|
|
// Harbour: hb_Hash, hb_HGet, hb_HSet, hb_HDel, hb_HHasKey, etc.
|
|
package hbrtl
|
|
|
|
import "five/hbrt"
|
|
|
|
// HbHash creates a hash from key-value pairs.
|
|
// Harbour: hb_Hash(key1, val1, key2, val2, ...) → hHash
|
|
func HbHash(t *hbrt.Thread) {
|
|
nParams := t.ParamCount()
|
|
t.Frame(nParams, 0)
|
|
defer t.EndProc()
|
|
|
|
h := hbrt.MakeHash()
|
|
hh := h.AsHash()
|
|
for i := 1; i <= nParams-1; i += 2 {
|
|
hh.Set(t.Local(i), t.Local(i+1))
|
|
}
|
|
t.PushValue(h)
|
|
t.RetValue()
|
|
}
|
|
|
|
// HbHGet gets a value from a hash by key.
|
|
// Harbour: hb_HGet(hHash, xKey) → xValue
|
|
func HbHGet(t *hbrt.Thread) {
|
|
t.Frame(2, 0)
|
|
defer t.EndProc()
|
|
hh := t.Local(1).AsHash()
|
|
if hh != nil {
|
|
if i := hh.Lookup(t.Local(2)); i >= 0 {
|
|
t.PushValue(hh.Values[i])
|
|
t.RetValue()
|
|
return
|
|
}
|
|
}
|
|
t.PushNil()
|
|
t.RetValue()
|
|
}
|
|
|
|
// HbHSet sets a value in hash by key.
|
|
// Harbour: hb_HSet(hHash, xKey, xValue) → hHash
|
|
func HbHSet(t *hbrt.Thread) {
|
|
t.Frame(3, 0)
|
|
defer t.EndProc()
|
|
hVal := t.Local(1)
|
|
if hh := hVal.AsHash(); hh != nil {
|
|
hh.Set(t.Local(2), t.Local(3))
|
|
}
|
|
t.PushValue(hVal)
|
|
t.RetValue()
|
|
}
|
|
|
|
// HbHDel deletes a key from hash.
|
|
// Harbour: hb_HDel(hHash, xKey) → hHash
|
|
func HbHDel(t *hbrt.Thread) {
|
|
t.Frame(2, 0)
|
|
defer t.EndProc()
|
|
hVal := t.Local(1)
|
|
if hh := hVal.AsHash(); hh != nil {
|
|
hh.Delete(t.Local(2))
|
|
}
|
|
t.PushValue(hVal)
|
|
t.RetValue()
|
|
}
|
|
|
|
// HbHHasKey checks if hash contains a key.
|
|
// Harbour: hb_HHasKey(hHash, xKey) → lExists
|
|
func HbHHasKey(t *hbrt.Thread) {
|
|
t.Frame(2, 0)
|
|
defer t.EndProc()
|
|
hh := t.Local(1).AsHash()
|
|
t.PushBool(hh != nil && hh.Has(t.Local(2)))
|
|
t.RetValue()
|
|
}
|
|
|
|
// HbHKeys returns an array of hash keys.
|
|
// Harbour: hb_HKeys(hHash) → aKeys
|
|
func HbHKeys(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
hh := t.Local(1).AsHash()
|
|
if hh != nil {
|
|
t.PushValue(hbrt.MakeArrayFrom(hh.Keys))
|
|
} else {
|
|
t.PushValue(hbrt.MakeArray(0))
|
|
}
|
|
t.RetValue()
|
|
}
|
|
|
|
// HbHValues returns an array of hash values.
|
|
// Harbour: hb_HValues(hHash) → aValues
|
|
func HbHValues(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
hh := t.Local(1).AsHash()
|
|
if hh != nil {
|
|
t.PushValue(hbrt.MakeArrayFrom(hh.Values))
|
|
} else {
|
|
t.PushValue(hbrt.MakeArray(0))
|
|
}
|
|
t.RetValue()
|
|
}
|