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

Remove Type() interface from aggregation stage #3045

Merged
merged 5 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove redundant db call
  • Loading branch information
chilagrow committed Jul 13, 2023
commit 74d7b687eb4528e6d8825baa6478a73f0468fdea
10 changes: 2 additions & 8 deletions internal/handlers/pg/msg_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,21 +402,15 @@ func processStagesStats(ctx context.Context, closer *iterator.MultiCloser, p *st

if hasCount || hasStorage {
if err = p.dbPool.InTransactionRetry(ctx, func(tx pgx.Tx) error {
var exists bool

if exists, err = pgdb.CollectionExists(ctx, tx, p.db, p.collection); err != nil {
return err
}

if !exists {
collStats, err = pgdb.CalculateCollStats(ctx, tx, p.db, p.collection)
if errors.Is(err, pgdb.ErrTableNotExist) {
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrNamespaceNotFound,
fmt.Sprintf("ns not found: %s.%s", p.db, p.collection),
"aggregate",
)
}

collStats, err = pgdb.CalculateCollStats(ctx, tx, p.db, p.collection)
return err
}); err != nil {
return nil, lazyerrors.Error(err)
Expand Down
11 changes: 2 additions & 9 deletions internal/handlers/pg/pgdb/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package pgdb

import (
"context"
"errors"
"fmt"

"github.com/jackc/pgx/v5"
Expand Down Expand Up @@ -144,14 +143,8 @@ func CalculateCollStats(ctx context.Context, tx pgx.Tx, db, collection string) (
var res CollStats

metadata, err := newMetadataStorage(tx, db, collection).get(ctx, false)

switch {
case err == nil:
// do nothing
case errors.Is(err, ErrTableNotExist):
return &res, nil
default:
return nil, lazyerrors.Error(err)
if err != nil {
return nil, err
}

// Call ANALYZE to update statistics, the actual statistics are needed to estimate the number of rows in all tables,
Expand Down