« first day (3820 days earlier)      last day (1038 days later) » 

8:52 AM
Bless me Father, for I have sinned! "What troubles you, my son?" Against my better judgement, I succumbed to the sin of posting when the OP hadn't responded to requests for more information Father! "Well, that's not too serious...". There's more father, (now tearful...), I, I (stammers...) engaged in commenting Father, multiple times...
"Oh dear! This changes matters.... You can...". (Sobs come from through the grille) There's yet more Father... "What can it be, my child?"... Father, I engaged in the shameful act of sarcasm!" (Expresses surprise) "My child!?" Yes, Father, and what's even worse is that I blasphemed!" (Coughing and spluttering comes from priest's side of grille - hoarse, but stern, voice "Go on!".
I paraphrased a koan of the infidels Father!" "Very well, as these matters are not mortal sins, but serious venial ones,
I'm giving you the following penance - you shall delete 50 comments, and clear the review queues twice a day for a week and finally, you shall write out Codd's laws 12 times, in copperplate in your copybook and show it to me next week!". Yes Father, thank you Father White... (pentient leaves, head bowed)...
It's this question:
0
Q: One-row postgres query as CTE/subquery much slower when passing subquery field into function / maybe related to inlining?

LaVacheI'm using postgres 13.3 with inner and outer queries that both only produce a single row (just some stats about row counts). I can't figure out why Query2 below is so much slower than Query1 (they should basically be almost exactly the same, maybe a few ms difference at most)... Query1: This quer...

I would like advice from older (well....) or wiser (certainly) heads than mine. At what point should I stop responding to an OP who seems to ignore my entreaties for more info. This guy posts PLANs with tables that he doesn't refer to in his question (I'm assuming VIEWs and ask about them), but don't get anything back... At what point should I stop responding - it's an interesting question but I think that I'm flogging a dead horse...
He then edited his post some 6 hours ago (i.e. at ~ 03:00 UTC) talking about "some kind of "Schrodinger's cat" - which is appropriate, since we haven't been given all information... I think the OP may have found a bug in PostgreSQL, but can't tell unless he provides a test case... anyway, just venting this morning - a chairde. Good morning all!
Just off to carry out my penance - by removing my comments from that question - I'll leave one just to let the OP know what I think of his responding to FoI request skills (i.e. more info - the FoI thing is to do with the Freedom of Information Act here - currently under "refinement"...)
 
@Vérace it's not a bug that one gets different plans to different queries. It's not a bug if one gets different plans for the same query!
 
@ypercubeᵀᴹ I'm not saying that's the bug - the optimiser is failing to recognise that the final part of the query is just one op on one result?
I appreciate that query plans can differ for all sorts of reasons (cardinalties, indexes... phases of the moon...) - but I thought that the WITH cte_name AS [ NOT ] [ MATERIALIZED ] should have put this one to bed?
 
9:14 AM
It should, yeah.
But we haven't seen what exactly the queries are (with MATERIALIZED)
or have a dbfiddle to play around and reproduce
 
morning
 
@ypercubeᵀᴹ - I asked for all that - but it appears that all the OP wants to do is moan about Schrodinger's cat!
 
The question has all the details you need.
And none of them.
As for when you should disengage, well that's a personal thing. It doesn't seem too messy so far.
But if it's really not answerable yet (despite the answer!) vote to close.
One never knows whether there's an interesting question or just an OP being an OP.
 
The answer solves the proximal problem - the distal one is, I believe, a PostgreSQL internals thing - and maybe even out of scope here - it's down to source code...
 
I see.
At least I think I will once I have looked up "distal".
Adjective: distal (comparative more distal, superlative most distal)
  1. (anatomy, geology) Remote from the point of attachment or origin.
  2. (dentistry) Facing the wisdom tooth or temporomandibular joint on the same side of the jaw.
  3. (linguistics) Far or farther from the speaker.
Dentistry lol
Q & A is like pulling teeth sometimes
 
9:29 AM
@Vérace you can add to your answer that one difference between the 2 plans provided (what I can see, I may have missed something else) is that the first (faster) one has Parallel Seq Scan on xformula xformula_1 while the 2nd has Seq Scan on xformula xformula_1.
That may well explain the different between 42 and 269 sec.
Other suggestion they can try (feel free to add them in your answer), is to separate the 3 aggregations in 3 (MATERIALIZED) CTEs, not all in one.
 
Jan 19 '18 at 1:19, by Paul White
Postgres doesn't run on Windows. It peaks at a fast walk.
 
what? ah, missed the joke at the first reading ;)
 
😀
 
@Vérace and add a link to Parallel plan tips
 
@ypercubeᵀᴹ I'll put it in later - enjoying a coffee - and to be honest, I'll probably hear the whooshing sound of it going over the OP's head from where I'm sitting! BTW, what do you think of my wrapping idea? That should skirt the fence?
I was actually thinking of using the deadly generate_series to run up a test case and try it out - may ask a question of my own - though it may be an internals thing?
 
9:36 AM
@Vérace yeah, maybe
Not too fond of extra wrapping to be honest ;)
 
Inelegant to be sure - but then it's only proximal! :-)
And the CASE works without any wrapping! Servers are not UIX tools!
 
The problem may just go away if they separate the 3 aggregations. Or it might get worse, who knows!
Another subquery wrap of a function with a CASE on a wrap on CTEs (with OFFSET and MATERIALIZED) and inline subqueries ... It looks like they are trying their best to confuse the optimizer. And succeeding very well.
 
Give enought people chainsaws and you're bound to get accidents!
 
 
4 hours later…
2:11 PM
@ypercubeᵀᴹ - fiddles 1, 2 & 3 - first is tables only, no functions, 2nd is views only, no functions and the third is views only with functions.
Plans for 1, 2 and 3 are here, here and here. The major difference that I can see is that plan 3 is shorter but has no parallel seq scans and takes twice as long! Any comments or observations?
If you need any more info, let me know. Oh, the plans I've shown are from 3 different instances of PostgreSQL run wtih 10,000,000 (10M) records in test_1 - couldn't do that on dbfiddle! :-)
Looks like you were on the money - but I'm still puzzled - the Parallel stuff only appears to make the fxn query half as fast - but the OP finds it to be 20% as fast... (here )... any comments?
3 different instances so there's no caching that we don't know about going on! Could the OP have 4 (or some relatively high) number of processors and the system is being throttled by this? My system only show 2 workers - I have 2 cores with 4 processors according to the spec.
But, looking at dbfiddle - there's no Parallel seq scans - minimal hardware?
 
 
3 hours later…
5:17 PM
@Vérace probably. You should ask Jack about that.
and whether it's possible to change parallel cost settings
 
 
1 hour later…
6:23 PM
@ypercubeᵀᴹ - I looked again at the OP's plans - the huge difference is the HASH JOINs - 243s vs. 43s (6 fold diff) - is this related to the scans? I"m not expert in reading plans - (yet, it's very much on my to-do list) - but the scans don't appear to be that much longer 9s & 3s (slow) vs. 1.3s each (fast). So, we know that the OP has an MP machine - he has 7 workers (8 core machine?) - this would kinda explain the 5/6 fold diff? I wish I knew WTF the OP was doing behind the scenes!
 
 
1 hour later…
7:25 PM
Final post (for today) - check out the last snippet here (tables) - also here (views) - the function doens't act as an optimisation fence when you MATERIALIZE the CTE... I don't know what the OP did with [ NOT ] [ MATERIALIZED ] - but there's a problerm with his question!
Oíche mhaith a chairde - Night all...
 

« first day (3820 days earlier)      last day (1038 days later) »