
Filter push down plus SQL perf testing
Some new modeling work to enable filter push down into joined views, plus a bunch of testing framework on our side to understanding ongoing model improvement work.
Transcript
This transcript is auto-generated. Names and product terms may be wrong.
Um, I have kind of a rambly one. Um, so I'll make I'll try to make it concise, but I got sniped this week into something that I wasn't planning on doing. Um, so the first thing is that we've renamed applies to, which was demoed a few weeks ago, to bind to to be more consistent with the existing bind param and query views.
And then what I noticed is that or you know I think some people notice is that this actually applies after the joins have happened. So it's not exactly like a parameterized wear. Um when we have this new param called prefer filtering view before join and this will do a filter push down. So if you have a join tree and originally that wear clause is going to be applied after the join and after aggregation.
This is kind of like a little optimization pram that's like actually I know that this field is only applying to this view and when I filter on it I want to do the filter before I join. So you can see it changes the the SQL that we generate to do this select star where the uh where the filter is being applied before the join.
Um, so that's like a cool little thing, right? And like, oh well, you know, maybe we should just do that for everything. Like anytime we notice that there's a field that's being filtered on and it's only being it's only referencing a single view, maybe we should always do the filter push down. Um, and we have, you know, I was like, okay, maybe we can experiment with this model feature, right?
Just model wide. Anytime you notice that there's like a filter being applied only to a single uh a field with only a single view reference, just do this optimization. But then they got me on this, you know, this uh this is where I got sniped where it's like we have no idea because currently we aren't doing any kind of like benchmarking or performance metrics based on like the actual query execution time.
Like if I enable this for everybody, I actually don't know if this is actually improving query performance for all dialects. Um and then I started looking into benchmarks and there's the TPCDS which is this kind of industry standard decision support benchmarking data set. Um, and so I got, you know, kind of into that. Uh, there's a data generator that Trino support or supported by Trino.
It's a free library. So I got that into our codebase and then started generating these enormous data sets um to run these performance tests that Claude also helped generate which is nice. Um, so now we have like this full loop of these really big tables much larger than what we use for correctness tests of like, you know, are the results correct?
If we change the SQL, does it does it still um the right the right results? Um, so these are like 20 million rows and 18 tables with crazy joins. And you can increase the complexity as well. U so that's now we got these benchmark tests which is cool. So I can just run them. They're pretty quick. benchmark comparison and it'll generate these JSON expectations and I have a script that will take the JSON and turn it into a CSV and it's like okay well now I can like go back to Omni and compare the previous run with the new run but I was manually like taking the CSV and dragging it in the UI and that got really annoying.
So as part of this I was like okay well I should make an API endpoint that actually handles uploads. So now as part of that it's like okay I wanted to do this benchmark stuff but now it's like okay we added a uh API endpoints for getting uploads that exist for a certain connection deleting uploads and then posting new uploads to a model.
So that's what I've been using to like refresh the the benchmarks. Um so I will upload the new ones. Um so I just updated question mark test on the uh on the push down stuff. Um yeah do we have intelligence in terms of understanding whether the push down um impacts the shape of the query.
So what I mean by that is if we're pushing down into the base view it's obviously going to like reduce the rows and we'll get fewer things. If you push down into a join view in a topic, we're probably g like there's a good chance that you'll get nulls in the join instead of um reducing the rows like you would in a typical topic.
How are you sort of thinking about the like whether the optimizer can figure out the difference and like when one should apply and when one shouldn't apply? Um, that's kind of like I naively added this this thing that's just like if you notice this pattern of like it's only being filtered on this single or like it's only affecting this one view, just do the push down.
And I think you're you're already seeing the problem with that. Like there's certain join paths where like you would just assume that the database optimizer will handle this. And it probably is doing a better job than we would do right now. And that's kind of what this performance benchmark found is like that change actually causes certain query shapes to perform worse.
And so this is the I don't know if you can see like every time I run it, it's just a little slower. And there's uh two queries in particular that really slow down. So on the left here is like the new with the filter push down always enabled and then on the right is without it. So there's two queries at least for Postgress and I'm going to I want to do this for all dialects but right now it's just Postgress.
These two queries perform like way worse right? So this SQL is the new updated SQL. You can see there's the left join and that's creating a ton of nulls that it doesn't actually reduce the the record size. And then this is the original SQL. Um, so I'm I'm excited to have this in the toolkit to be able to be like, okay, if I make a SQL change, do I really just want to just send it out and you know correctness is still there because the results are the same, doesn't change the results, but now we have this performance metric that we can actually refer to, which is kind of nice.
And then you can use Omni to debug it as well. So I have the query plans and do explain. Um and the difference here this just in time compilation thing that Postgress adds um I think adds some overhead that makes it slower and then you know you're not actually reducing the size because now you just have nles that you're joining on.
So there's stuff that we can do here to improve this and actually make that work. But um yeah, so that was that's kind of why it's it's a bit of a ramble. So thanks for listening. But at least two real things, the prefer filter optimization and then the uploads APIs. Those are real. The performance benchmark is awesome.
That's great. We will definitely want to do that. And like I can imagine using it for like aggregate horniness and and you know our stuff, right? Yeah. So, so this is like kind of a simple case, but the all of the weird stuff that we do like period over period and level of detail and the multi-topic was why I got started thinking about this to begin with because the outer query joins are going to be very very ugly.
Right. Thank you.