Loading
rows: implement driver.RowsColumnScanner on Go 1.27
Go 1.27 added driver.RowsColumnScanner: when a driver implements it, database/sql calls NextRow and ScanColumn instead of Next, so the driver can store a column straight into the Scan destination. With Next, every INTEGER and FLOAT value is boxed into a driver.Value, which allocates once per value outside 0–255.
This MR implements it behind //go:build go1.27, so the module keeps building on Go 1.26:
NextRowsteps without converting columns.ScanColumnstores INTEGER into*int64/*float64and FLOAT into*float64/**float64directly, NULL into**float64as nil._inttotimecolumns are skipped.- Every other column type or destination goes through the existing conversion, moved unchanged from
Nextintorows.value, followed bysql.ConvertAssign, so results and errors are the same as withNext.Nextitself now callsrows.valueand keeps working for older Go.
BenchmarkScanColumn (10,001 rows of int64, float64, darwin/arm64):
| ns/op | B/op | allocs/op | |
|---|---|---|---|
| Next | 1,844,000 | 320,535 | 30,016 |
| RowsColumnScanner | 1,482,000 | 160,485 | 10,013 |
In a real workload (evcc energy history, a GROUP BY over 35k slots scanned into float64 and *float64 fields, linux/arm64) allocations drop from 446k to 175k per query. go test . passes on darwin/arm64 with go1.27.2.