Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement limit pushdown for PostgreSQL #3580

Merged
merged 17 commits into from
Oct 18, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
noisersup committed Oct 18, 2023
commit baf8cd7676ab61aca539d62b79ea4aaef90faea4
6 changes: 5 additions & 1 deletion internal/backends/sqlite/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@
}, nil
}

if params == nil {
params = new(backends.QueryParams)
}

Check warning on line 69 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L67-L69

Added lines #L67 - L69 were not covered by tests

var whereClause string
var args []any

// that logic should exist in one place
// TODO https://github.com/FerretDB/FerretDB/issues/3235
if params.Filter.Len() == 1 {

Check warning on line 76 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L76

Added line #L76 was not covered by tests
v, _ := params.Filter.Get("_id")
if v != nil {
if id, ok := v.(types.ObjectID); ok {
Expand All @@ -87,11 +87,11 @@

q := fmt.Sprintf(`SELECT %s FROM %q`+whereClause, metadata.DefaultColumn, meta.TableName)

if params.Limit != 0 {
q += ` LIMIT ?`
args = append(args, params.Limit)

Check warning on line 92 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L90-L92

Added lines #L90 - L92 were not covered by tests
}

Check warning on line 94 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L94

Added line #L94 was not covered by tests
rows, err := db.QueryContext(ctx, q, args...)
if err != nil {
return nil, lazyerrors.Error(err)
Expand Down Expand Up @@ -248,13 +248,17 @@
}, nil
}

if params == nil {
params = new(backends.ExplainParams)

Check warning on line 252 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L251-L252

Added lines #L251 - L252 were not covered by tests
}

Check warning on line 254 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L254

Added line #L254 was not covered by tests
var queryPushdown bool
var whereClause string
var args []any

// that logic should exist in one place
// TODO https://github.com/FerretDB/FerretDB/issues/3235
if params != nil && params.Filter.Len() == 1 {
if params.Filter.Len() == 1 {

Check warning on line 261 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L261

Added line #L261 was not covered by tests
v, _ := params.Filter.Get("_id")
if v != nil {
if id, ok := v.(types.ObjectID); ok {
Expand All @@ -269,14 +273,14 @@

q := fmt.Sprintf(`EXPLAIN QUERY PLAN SELECT %s FROM %q`+whereClause, metadata.DefaultColumn, meta.TableName)

var limitPushdown bool

if params.Limit != 0 {
q += ` LIMIT ?`
args = append(args, params.Limit)

Check warning on line 280 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L276-L280

Added lines #L276 - L280 were not covered by tests
limitPushdown = true
}

Check warning on line 283 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L282-L283

Added lines #L282 - L283 were not covered by tests
rows, err := db.QueryContext(ctx, q, args...)
if err != nil {
return nil, lazyerrors.Error(err)
Expand Down
Loading