From e88c18985d3441c2147e4090b3017ffe5a380227 Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Sat, 23 Apr 2022 15:59:40 -0400 Subject: [PATCH] fix: add constraints for `github_repo_prs` table this enables an "early exit" optimization which will tell the `vtab` library to avoid a full table scan in certain cases when a WHERE and ORDER BY clause are used --- extensions/internal/github/repo_prs.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/extensions/internal/github/repo_prs.go b/extensions/internal/github/repo_prs.go index 4f912827..48b7835b 100644 --- a/extensions/internal/github/repo_prs.go +++ b/extensions/internal/github/repo_prs.go @@ -317,9 +317,15 @@ var prCols = []vtab.Column{ {Name: "changed_files", Type: "INT"}, {Name: "closed", Type: "BOOLEAN"}, {Name: "closed_at", Type: "DATETIME"}, - {Name: "comment_count", Type: "INT", OrderBy: vtab.ASC | vtab.DESC}, + {Name: "comment_count", Type: "INT", OrderBy: vtab.ASC | vtab.DESC, Filters: []*vtab.ColumnFilter{ + {Op: sqlite.INDEX_CONSTRAINT_GT}, {Op: sqlite.INDEX_CONSTRAINT_GE}, + {Op: sqlite.INDEX_CONSTRAINT_LT}, {Op: sqlite.INDEX_CONSTRAINT_LE}, + }}, {Name: "commit_count", Type: "INT"}, - {Name: "created_at", Type: "DATETIME", OrderBy: vtab.ASC | vtab.DESC}, + {Name: "created_at", Type: "DATETIME", OrderBy: vtab.ASC | vtab.DESC, Filters: []*vtab.ColumnFilter{ + {Op: sqlite.INDEX_CONSTRAINT_GT}, {Op: sqlite.INDEX_CONSTRAINT_GE}, + {Op: sqlite.INDEX_CONSTRAINT_LT}, {Op: sqlite.INDEX_CONSTRAINT_LE}, + }}, {Name: "created_via_email", Type: "BOOLEAN"}, {Name: "database_id", Type: "INT"}, {Name: "deletions", Type: "INT"}, @@ -342,7 +348,10 @@ var prCols = []vtab.Column{ {Name: "review_decision", Type: "TEXT"}, {Name: "state", Type: "TEXT"}, {Name: "title", Type: "TEXT"}, - {Name: "updated_at", Type: "DATETIME", OrderBy: vtab.ASC | vtab.DESC}, + {Name: "updated_at", Type: "DATETIME", OrderBy: vtab.ASC | vtab.DESC, Filters: []*vtab.ColumnFilter{ + {Op: sqlite.INDEX_CONSTRAINT_GT}, {Op: sqlite.INDEX_CONSTRAINT_GE}, + {Op: sqlite.INDEX_CONSTRAINT_LT}, {Op: sqlite.INDEX_CONSTRAINT_LE}, + }}, {Name: "url", Type: "TEXT"}, }