sqlcount

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sqlcount counts SQL statements, so a test can assert how work GROWS rather than how long it takes.

It lives in its own package because internal/testutil imports internal/ingest, and the walker's own tests need this.

Index

Constants

View Source
const DriverName = "sqlite-counting"

DriverName is the driver to open a database with when the test wants its statements counted. Call Register first.

Variables

This section is empty.

Functions

func RegisterDriver

func RegisterDriver()

RegisterDriver registers the counting driver, once per process.

The base driver is taken from an opened "sqlite" handle rather than constructed, so this stays correct if the sqlite package changes how it exports its driver.

func Reset

func Reset() (count func() int64)

Reset zeroes the counter and returns a func reading it.

The counter is process-global, so a test that reads it must not run in parallel with another that issues statements.

func ResetPrepares

func ResetPrepares() (count func() int64)

ResetPrepares zeroes the PREPARE counter and returns a func reading it.

A separate count from Reset because it measures a different thing. Every query EXECUTES once however it is issued, so an execution count cannot tell a reused prepared statement from one compiled afresh per call — and the compilation is the cost: a profile of a warm point read on the direct path showed SQLite's parser at ~half of all remaining time once page I/O was out of the way (mache-3063fb). A prepare count separates them: it scales with calls when a hot path hands database/sql a query STRING each time, and stays fixed when the statement is prepared once and reused.

Added per this file's own rule for counters: when a gate needs the number.

Types

type ReadCounted

type ReadCounted struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

ReadCounted is a read-only database whose file reads are counted.

func OpenReadCounted

func OpenReadCounted(path string) (*ReadCounted, error)

OpenReadCounted opens the database at path read-only, counting the bytes SQLite reads from its file. The page cache is per connection, so the count for a query includes the pages it had to fetch, not ones already cached by an earlier query on the same connection.

func (*ReadCounted) Close

func (r *ReadCounted) Close() error

Close closes the database, then unregisters its VFS.

func (*ReadCounted) Reset

func (r *ReadCounted) Reset() (bytes func() int64)

Reset zeroes the byte counter and returns a func reading it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL