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 pushdown for aggregate for PostgreSQL #3607

Merged
merged 10 commits into from
Oct 23, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
noisersup committed Oct 19, 2023
commit 883975c62a2b0be267f32596e892ade93ecff1f5
22 changes: 18 additions & 4 deletions internal/handlers/sqlite/msg_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
var iter iterator.Interface[struct{}, *types.Document]

if len(collStatsDocuments) == len(stagesDocuments) {
filter, _ := aggregations.GetPushdownQuery(aggregationStages)
filter, sort := aggregations.GetPushdownQuery(aggregationStages)

// only documents stages or no stages - fetch documents from the DB and apply stages to them
qp := new(backends.QueryParams)
Expand All @@ -268,9 +268,23 @@
qp.Filter = filter
}

//if h.EnableSortPushdown {
// qp.Sort = sort
//}
// Skip sorting if there are more than one sort parameters
if h.EnableSortPushdown && sort.Len() == 1 {
var order types.SortType

k := sort.Keys()[0]
v := sort.Values()[0]

order, err = common.GetSortType(k, v)
if err != nil {
return nil, err
}

Check warning on line 281 in internal/handlers/sqlite/msg_aggregate.go

View check run for this annotation

Codecov / codecov/patch

internal/handlers/sqlite/msg_aggregate.go#L273-L281

Added lines #L273 - L281 were not covered by tests
chilagrow marked this conversation as resolved.
Show resolved Hide resolved

qp.Sort = &backends.SortField{
Key: k,
Descending: order == types.Descending,
}

Check warning on line 286 in internal/handlers/sqlite/msg_aggregate.go

View check run for this annotation

Codecov / codecov/patch

internal/handlers/sqlite/msg_aggregate.go#L283-L286

Added lines #L283 - L286 were not covered by tests
}

iter, err = processStagesDocuments(ctx, closer, &stagesDocumentsParams{c, qp, stagesDocuments})
} else {
Expand Down
Loading