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
Fix featureCount on postgres view when flag estimatedmetadata is set #32114
Fix featureCount on postgres view when flag estimatedmetadata is set #32114
Conversation
Not sure about the backport 3.4 though. It's quite an easy fix, so I would say yes |
What's the consequence of the bug? Only fixes for crashes or data corruption should be backported now. |
What's the consequence of the bug?
If you choose the option "Use estimated table metadata" in PostGIS
connexion window and you want to add a view, the feature count will be
always 0.
It doesn't crash nor corrupt data. So, I remove the backport label.
|
Doesn't this make loading expensive views painfully slow? |
It surely does. I suggest to use EXPLAIN and parse its output, for estimating number of rows contained in a query. |
EXPLAIN could actually be also used for queries, dropping another performance bottleneck when user asked for "estimated" metadata... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think EXPLAIN should be used for the estimation
Isn't it dangerous to rely on EXPLAIN output to estimate the number of rows? How can we be sure that the output is not gonna change in the future, that someday |
Explain has XML output support since 9.0 (https://www.postgresql.org/docs/9.0/sql-explain.html). |
2a47c63
to
7352e3f
Compare
Thanks for the tip, I was not aware about explain formats. I choose JSON over XML, because it seems to me easy to write 7352e3f . |
7352e3f
to
f3705ab
Compare
should be guarded by |
OK, I'll add it (with 90000, this feature was already available in 9.0 )
And displaying -1 in the UI? or "Unknown"? |
f3705ab
to
5f43b3f
Compare
I let the feature count display as it is, so if the estimate doesn't work, it will display -1 |
@strk is it OK for requested changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks fine here
Anyone to merge this ? |
thanks @elpaso ! |
@troopa81 I understand why you made this change for views, it was indeed correct. The Look this example: EXPLAIN (FORMAT JSON) SELECT 1 FROM pgmetadata.contact
-- QUERY PLAN [{'Plan': {'Node Type': 'Seq Scan', 'Parallel Aware': False, 'Relation Name': 'contact', 'Alias': 'contact', 'Startup Cost': 0.0, 'Total Cost': 15.1, 'Plan Rows': 510, 'Plan Width': 4}}]
-- > 'Plan Rows': 510
VACUUM ANALYSE pgmetadata.contact;
SELECT reltuples as approximate_row_count FROM pg_class WHERE oid = 'pgmetadata.contact'::regclass;
-- 0.0
SELECT COUNT(*) FROM pgmetadata.contact;
-- 0
EXPLAIN (FORMAT JSON) SELECT 1 FROM pgmetadata.contact;
-- Still 510 |
Hum, I though indeed we would have this info already in the context.
My tables are indeed neatly all empty for now. But I tried with a simple line, it's still wrong. SELECT COUNT(*) FROM pgmetadata.contact;
-- 1
EXPLAIN (FORMAT JSON) SELECT 1 FROM pgmetadata.contact;
-- Still 510 Should I create a ticket ? |
It could be, I don't see any reason to retrieve this information several times
My guess here is that the Plan rows approach is more approximate than the reltuples one. I tried with a table containing 3+06 rows and removed all rows. The reltuples did say 0 while the Plan Rows says 300. Both have changed and both are kind of true for an estimation. But the reltuples is more true :)
Yes, please |
We can't estimate rows on postgres view.
Checklist
Fixes #11111
at the bottom of the commit messagescripts/prepare-commit.sh
script before each commit