All of a sudden the exact same query (from my point of view) takes almost 30s. I generated the original WHERE statement using the metabase query generator. What is being generated behind the scenes that is so inefficient?
Hey! You can view the SQL for any question if you open the query builder and click the little "console" icon in the top right (it will say "View the SQL" when you hover over it")!
Yes this I know. The query I generated using the query builder is working fine and responds in <1s. It the query written in native SQL with a date field filter that is not performing well. I assume this date field filter is being compiled to some form of SQL. How do I find this compilation? Because that’s the query that’s running slowly.
We've finally tracked the issue. It's because the field filter is using CAST("public"."player_games"."created_at" AS date) it's preventing our database from using the index on the created_at column. Which makes the query significantly slower than when just hard coding in date ranges. Which is annoying.
Is there any chance newer version of Metabase have better time based aggregation that doesn't block Postgres date indexes from being used? I'm using version 0.44.1
Yes this sounds exactly like what I’m running into. It makes the date field filter (one our most desired filters) basically useless because it prevents our database from using the index. It turns queries that take seconds to run and converts it into a query that takes hours to run.