I have a question in a dashboard where there are multiple values wanted for one of the columns.
Metabase creates this as part of the where clause:
AND (
(
"bi"."careslot"."care_type" <> 'Care (Live in Client)'
)
OR ("bi"."careslot"."care_type" IS NULL)
)
AND (
("bi"."careslot"."care_type" <> 'Live In')
OR ("bi"."careslot"."care_type" IS NULL)
)
AND (
(
"bi"."careslot"."care_type" <> 'Live in (Change Over)'
)
OR ("bi"."careslot"."care_type" IS NULL)
)
There are many, many more like that. Itās really inefficient as Postgres wonāt use any index. Even worse, that column canāt be null (this is a cleaned up materialised view).
Is there a way to stop this happening? Maybe in the options for the database connection?
So this is a multi-select filter with an Is Not operator, right?
Not sure there is any way this can be further optimized using the notebook editor. This type of condition works best paired with a sargeable inclusion predicate that gets used for the index lookup. If its a table scan with exclusions thereās no way to optimize it.
On top of that matviews donāt support not-null constraints, otherwise the āis nullā part of the condition can be optimized out.
Can you share more of the WHERE clause? Maybe we can see if another part can be enlisted to help.
Thereās no āNOTā, this is the inclusion criteria.
Iām asking the customer if there are āsetsā of these so I can just extend the MV or add a lookup.
Failing that, Iāll have to create a view on top of the MV and move the caretype into a lookup table where I could define it as non-nullable.
Iād not appreciated the problem with MVs not having the notion of nullable columns. I suppose I could do it more manually into a table but thereās a lot of records and refreshed regularly.
Frustrating.
The predicates you pasted are not-equal comparisons (<>), thatās where the āNOTā Iām referencing is coming from. The fragment you pasted is checking that care_type is not set to one of āCare (Live in Client)ā, āLive Inā, or āLive in (Change Over)ā.
That also doesnāt match with your first sentence in your first post, where you say you have āmultiple values wanted.ā
What you have here is multiple values NOT wanted.
At this point I donāt understand the problem youāre describing. Start at the beginning, show your inputs to Metabase, then show what output isnāt what you think it should be. If Metabase is generating the wrong query, thatās a bug that can be fixed. If query performance is poor, we can look at the question and its query and figure out how to improve performance.
That was quick - sorry, I just checked and it is a āIs Notā filter. I thought Iād have time to edit my response after having a shower (it is 7am)! Itās not one of my dashboards, so Iām not completely up to speed with it.
There are about 30 care types of which 5 are unwanted in this query. Theyāre always adding additional care types which is why theyāre using a not filter.
I think I need to add an extra column with index that can be used to include the filter values. They all contain āLive Inā so not a big deal to add.
Thanks for the help.
1 Like