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

MongoDB shouldn't do an initial projection for :default date bucketing #14838

Closed
camsaul opened this issue Feb 16, 2021 · 1 comment
Closed

Comments

@camsaul
Copy link
Member

camsaul commented Feb 16, 2021

Given a query like

(mt/dataset attempted-murders
  (mt/mbql-query attempts
    {:aggregation [[:count]]
     :filter      [:time-interval $datetime :last :month]}))

Which end up with a native query like this: (including #14835 optimizations):

[{"$project" {"datetime~~~default"
              {:$let {:vars {:column "$datetime"}, :in :$$column}}}}
 {"$match"
  {"$and"
   [{"datetime~~~default" {"$gte" {:___date "2021-01"}}}
    {"datetime~~~default" {"$lt" {:___date "2021-02"}}}]}}
 {"$group" {"_id" nil, "count" {"$sum" 1}}}
 {"$sort" {"_id" 1}}
 {"$project" {"_id" false, "count" true}}]

That initial projection is going to destroy potential usage of indexes, and we don't need it at all, since :default just means we explicitly do not want any extra temporal bucketing.

This is a subset of #4216. I fixed most of #4216 in #11832, but cases such as these are still causing initial projections... by solving this specific case we may be able to finally close #4216 entirely.

@camsaul
Copy link
Member Author

camsaul commented Feb 18, 2021

Implemented by #14840

@camsaul camsaul closed this as completed Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant