From: | Kim Rose Carlsen <krc(at)hiper(dot)dk> |
---|---|
To: | Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> |
Cc: | Merlin Moncure <mmoncure(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to hint 2 coulms IS NOT DISTINCT FROM each other |
Date: | 2016-10-29 13:27:41 |
Message-ID: | AM4PR0501MB26100F718260A4425280825EC7AC0@AM4PR0501MB2610.eurprd05.prod.outlook.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>> This doesn't do much good. This doesn't tell the planner that the 3
>> customer_ids are actually of same value, and it therefore can't filter them
>> as it sees fit.
> You do know you can index on a function, and the planner then keeps
> stats on it when you run analyze right?
Yes, but I don't think it will make any difference. I don't think I can solve this with
an index lookup. I think my savior is the inference that the 2 columns are of
same value and the planner are free to choose which order to do the filter and join
with this extra information.
I have tried creating a function called
zero_if_null(int) : int that just select COALESCE($1, 0)
and adding a index on (zero_if_null(customer_id)) on table that contains customer_id. The only thing I get from is the planner now only knows how to compare customer_id, but it still doesn't know that they are of same value, only I know that and I want to declare it for the planner.
I could probably rewrite the whole view in one query, and then fix it with a proper index. But I think I will loose alot of readability.
I could also change the structure to save an explicit state, instead of a calculated state. But then I get some redundancy I need to make sure always stays the same.
In the end one of these will probably be the solution.
I guess the question is more or less,
why doesn't IS NOT DISTINCT FROM behave the same way as = operator, are there any alternatives? And a plausible use case for when it would be useful.
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2016-10-29 13:28:50 | Re: initdb createuser commands |
Previous Message | Chris Mair | 2016-10-29 13:18:17 | Re: Best way to return Random rows from a table with non-repeatability of rows |