GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - boringSQL/qshape: AST-level fingerprint and cluster of PostgreSQL queries from pg_stat_statements

BranchesTags
Open more actions menu

Latest commit

 

History

46 Commits
46 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
cmd/qshape
cmd/qshape
 
 
scripts
scripts
 
 
tags
tags
 
 
testdata
testdata
 
 
.gitignore
.gitignore
 
 
.goreleaser.yaml
.goreleaser.yaml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
cluster.go
cluster.go
 
 
cluster_order_test.go
cluster_order_test.go
 
 
cluster_parallel_test.go
cluster_parallel_test.go
 
 
cluster_test.go
cluster_test.go
 
 
corpus_test.go
corpus_test.go
 
 
costkey.go
costkey.go
 
 
fingerprint.go
fingerprint.go
 
 
fingerprint_test.go
fingerprint_test.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
golden_test.go
golden_test.go
 
 
normalize.go
normalize.go
 
 
normalize_test.go
normalize_test.go
 
 
prettify.go
prettify.go
 
 
prettify_test.go
prettify_test.go
 
 
reshape.go
reshape.go
 
 
reshape_test.go
reshape_test.go
 
 
shape.go
shape.go
 
 
sortprofile.go
sortprofile.go
 
 
tables.go
tables.go
 
 
tables_test.go
tables_test.go
 
 
version.go
version.go
 
 
walk.go
walk.go
 
 

Repository files navigation

qShape

AST-level canonicalization and fingerprinting of PostgreSQL queries, plus a pg_stat_statements capture command that ranks workload by execution time, not just call count.

pg_stat_statements.queryid hashes the parse tree after literal-to-$N substitution but before any AST normalization. ORMs (Rails, ActiveRecord, SQLAlchemy, Prisma, Sequelize) produce many queryids for one logical query shape. qshape collapses those variants to a single canonical fingerprint and aggregates their timing.

qShape is part of the boringSQL stack alongside RegreSQL, Fixturize and dryrun.

Measured corpus reduction

Typical reduction on an ORM-heavy pg_stat_statements snapshot is 30–50%. Enough that per-shape timing aggregates stop fragmenting across near-duplicate queryids. The upper bound depends on how much of the workload is alias / predicate-order variation vs. genuinely distinct shapes.

On one real production snapshot we measured 4,716 distinct queryids to 177 canonical fingerprints (96.2% reduction) — an outlier, driven by heavy ORM alias churn on a small set of underlying query shapes. See reshape.go for the AST transformations that drive the collapse.

Install

Homebrew:

brew install boringsql/boringsql/qshape

From source:

go install github.com/boringsql/qshape/cmd/qshape@latest

Pre-built binaries for macOS and Linux (amd64 + arm64) are published on each release via GoReleaser.

CLI

qshape normalize "SELECT u.id FROM users u WHERE u.id = 1"
SELECT.id FROM users u WHERE id = 1

qshape fingerprint "SELECT id FROM users WHERE id = 1"
sha1:63fe28385e8b4d95

qshape capture "postgres://user:pass@host/db" > queries.json

qshape attribute --in clusters.json --conn "$DATABASE_URL" > queries-attributed.json

capture connects directly to a PostgreSQL node and reads pg_stat_statements with original whitespace and timing intact, then writes {"clusters":[...]} to stdout sorted by descending total_exec_time_ms. Passing - (or omitting the SQL arg) to normalize / fingerprint reads stdin.

qshape also harvests structured comments (sqlcommenter, marginalia, sqlc / boringSQL headers, bare comments) into per-cluster owners and regresql_meta fields.

Learn more

  • boringSQL, the blog and project home
  • RegreSQL, regression testing for PostgreSQL queries
  • Fixturize and dryrun, companion tools in the suite

License

BSD 2-Clause.

About

AST-level fingerprint and cluster of PostgreSQL queries from pg_stat_statements

boringsql.com/

Topics

astclipg-stat-statementspostgresql

Resources

Readme
BSD-2-Clause license
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.