Skip to content

Commit 590953f

Browse files
committed
chore: explain options
1 parent 16401b6 commit 590953f

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

regresql/baseline.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,33 @@ func getBaselinePath(q *Query, baselineDir string, bindingName string) string {
3838
return baselinePath
3939
}
4040

41-
// ExecuteExplain runs EXPLAIN (FORMAT JSON) for a query and returns the parsed plan
41+
// ExplainOptions configures EXPLAIN execution
42+
type ExplainOptions struct {
43+
Analyze bool // Execute query and show actual timing/rows (default: false)
44+
Buffers bool // Show buffer usage statistics (default: false)
45+
Verbose bool // Show additional output (default: false)
46+
}
47+
48+
// DefaultExplainOptions returns safe defaults (no ANALYZE, no BUFFERS)
49+
func DefaultExplainOptions() ExplainOptions {
50+
return ExplainOptions{
51+
Analyze: false,
52+
Buffers: false,
53+
Verbose: false,
54+
}
55+
}
56+
57+
// ExecuteExplain runs EXPLAIN (FORMAT JSON) with default options (ANALYZE=false)
4258
func ExecuteExplain(q Querier, query string, args ...any) (*ExplainOutput, error) {
43-
explainQuery := fmt.Sprintf("EXPLAIN (FORMAT JSON, ANALYZE false, VERBOSE false, COSTS true, BUFFERS false) %s", query)
59+
return ExecuteExplainWithOptions(q, query, DefaultExplainOptions(), args...)
60+
}
61+
62+
// ExecuteExplainWithOptions runs EXPLAIN (FORMAT JSON) with configurable options
63+
func ExecuteExplainWithOptions(q Querier, query string, opts ExplainOptions, args ...any) (*ExplainOutput, error) {
64+
explainQuery := fmt.Sprintf(
65+
"EXPLAIN (FORMAT JSON, ANALYZE %t, VERBOSE %t, COSTS true, BUFFERS %t) %s",
66+
opts.Analyze, opts.Verbose, opts.Buffers, query,
67+
)
4468

4569
rows, err := q.Query(explainQuery, args...)
4670
if err != nil {

0 commit comments

Comments
 (0)