-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
Changed plan (possible regression) in FB 5.x / 6.x comparing to FB 3.x / 4.x #7909
Comments
Both LEFT JOINs are converted into INNER here, so the optimizer attempts to evaluate possible table permutations. Condition |
I've forwarded this question to the customer, waiting for reply.
0.000399680255213752389 |
It would also be useful to see stats (execution time & fetches) for v4, v5 and v5 without +0 in the last condition. |
So the number of rows with CreateEmpID = 999999 at the moment is 771402 and the selectivity is 0.000399680...... with FromDateTime = '01.10.2023' FB5 doesn't return anything in hours (we killed the statement after waiting for more than 6 hours) regardless if there is +0 or not in the last statement. If I remove the whole statement about CreateEmpID in InvoiceH the query runs in milliseconds with the following stats `
|
Тhe question is why is FB5 trying to change the JOINs from LEFT OUTER to INNER ones and is there any way we can force it NOT to do it? |
It does it because it allows more optimization abilities (different join orders). As for forcing it to avoid that, see #7910 - it's exactly about that. If you're OK with such a solution (configuration option), it will be added to RC2. |
Yes, this configuration option will be very useful for us and we are really looking forward for you releasing a version that supports it. |
So you ask for 80% of rows while the optimizer expects less than a thousand to be returned. Such a skewed value distribution is impossible to optimize properly without histograms. Their usage is also limited (only for constant parameters), but at least they provide an option. |
yes, that's absolutely right and that's exactly the reason why we did our best to "hint" the optimizer not to try to use this field/index (by using the 0+ih.CreateEmpID syntax) ... but unluckily it tried to be smarter than what we expected ... and failed badly |
In addition to what dimitr said. There are suspicions that in the above example, parentinvoiceid contains many NULLs. The index invoicehbyparentinvoiceiddesc does not contain NULL selectivity. This means that its real selectivity for equality is distorted. Thus, the OR bitmask predicts poor selectivity, which may affect the join order. |
You can try to create a partial index to replace the existing one. drop index invoicehbyparentinvoiceiddesc;
create descending index invoicehbyparentinvoiceiddesc
on invoiceh (parentinvoiceid) where (parentinvoiceid is not null); |
I did try it but it doesn't change anything ... and to be honest I don't see how it will since there is no meaningful filtering on this table by ParentInvoiceID and expectedly the plan remains "JOIN (IH NATURAL, PH INDEX ....). But there is a good news - if we do set the option OuterJoinConversion to false everything returns back to a working state and the query runs in 2.3sec. I just hope that this comment for the option in the .config file will not materialize
|
On the contrary, I hope that it will be. Because this parameter is not a solution to the problem, but a crutch. I would prefer real hints for hints to the optimizer. And it would be even better if he could do without hints at all, but this is from the realm of fiction, so even in DBMS with good optimizers there are hints |
Actually, PostgreSQL doesn't allow optimizer hints. If you ask for hints to make the query planner do X, the developers tell you to send them the query instead and they'll make sure the query planner does X from now on! :-) |
So far we were doing the same ;-) But it cannot solve all the issues, because the optimizer intelligence is limited, regardless of how good it is. |
Problem was reported by one of our customer privately.
Consider script from attached .zip
ddl-and-run_-_for-empty-tables.sql.zip
Query that caused problems in customer environment has following plans:
Customer states that second plan leads to performance problem.
Additional data from customer:
The text was updated successfully, but these errors were encountered: