fwiw, i did test it just now and the plan improved but this particular recording would be in cache now so better to test on some other recording
wargreen has quit
mayhem
yep!
lucifer
The issue here is the same as the one in https://github.com/metabrainz/listenbrainz-serv... . If your query exceeds 8 JOINs (including FROM iirc), PG will opt to use a probablistic optimizer instead of trying out all possible options. This happens to save planning time.
mayhem
working much better, even with totally new recordings not in cahce.
and MATERIALIZED changes this how?
lucifer
when you added release group JOIN, it crossed the limit. so one solution is to do what we do in mb metadata cache. increase the limit above which the optimizer degrades to a probablistic one.
the other one is force the CTE to evaluated separately from the rest of the query.
with materialized PG will see this as two separate queries, `1 CTE with 4-5 joins, then the main query with 4-5 JOINs
both on their own are below the threshold so are optimized well.
mayhem
ah, got it. ok, will remember this. I hope. ;)
lucifer
without materialized, the CTE is merged into the main query and it becomes 1 query with 8-9 joins that crosses the limit.
if your query has 8-9 joins, it'll probably hit this issue which may or may not be a perf issue. it depends on how you write the query. if your cte had begun with recording then joined to track then to medium to release it would probably have been faster and you might not have noticed the issue.
its the job of the optimizer that hits the limit to reorder the joins optimally automatically and the optimizer changes at the limit so the issue.
lucifer ends rant
mayhem
:) thanks for the rant.
I wonder if subsequent version of PG improve on this.
lucifer
maybe but materialized was probably the improvement they made so that users could control the cte behavior to their needs.
iirc, the story of the materialized bit is somewhat funny. it used to be the only possible thing till PG 10, always materialize. and served the purpose of optimization fence, you could use it to break the plan to your needs. so ctes were different from subqueries which would always be merged with the main query.
then it was changed in PG 11 to be non-materialized whenever possible so that broke people's workarounds who had been using CTEs for keeping queries separate. so in PG 12 they retained the default from 11 but they added the materialized/not materialized option to let users configure it on per cte basis.
lucifer ends it for real this time
mayhem
lol. hard earned knowledge, I see. :)
lucifer
yeah been bitten many times by this
we ran TS on PG 11 whereas MB on PG 12 till earlier this year so ...
mayhem
that's just it -- its "bitten" thing. you'd expect that these sorts of thresholds to be ironed out over time.
lucifer
yup makes sense
mayhem
however, lets take a moment for some perspective.
this is purely amazing free software.
which functions many times better than any paid software I've ever used. esp if it was from M$
PG has bitten us very few times in the past 20 years or so. which is amazing.
lucifer
indeed indeed, definitely agree.
and other databases paid or not, are not without their quirks. PG is awesome
lucifer: still getting “Youtube player error. The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.” today unfortunately, haven’t listened in a few days to see what happens
Shall I make a ticket?
reosarevok
outsidecontext: neat! What did they say?
aerozol
Also can we tweak anything so the error message doesn’t just show html code/the href? Or is that just because we’re displaying what YouTube is sending. Might not be worth worrying about if so
outsidecontext
I think the bottom line is that we should not make assumptions about the IDs themselves, as they depend on the entity being linked to, but we can make assumptions about URL structure. I'll forward you the e-mail with some comment.
aerozol: huh, i see in youtube api dashboard that quota is indeed being exceeded. weird
aerozol
You said it’s quite high right? So either a exploit or an error (bad) or been getting used heaps (pretty good!)?
lucifer
mayhem: hi! when you have time, can you open the google cloud console dashboard and see if you can edit quotas for youtube api? i don't see the extended quota limit anywhere maybe something we need to enable manually.
aerozol: yeah, i don't see the high limit being enforced. the old low limit is being used as of now
aerozol
I can’t listen with Spotify if I don’t have premium right (I’m finally about to join the daily jams party)