
Eliminating double query planning
More behind the scenes perf work.
Transcript
This transcript is auto-generated. Names and product terms may be wrong.
All right, I had another little demo. Um, one of the things that has sort of bugged me about the way things work at Omni, um, and this is a little bit more behind the scenes, but it may, uh, um, it may prove helpful in the future. Um, one of the things that bugged me a fair amount is that every time I'm going to start actually over on playground.
Um, so this is what it looks like today. is every time you run a query when you are sort of exploring or using the workbook page um you'll notice is that when I click on users count it kicks off two um requests here. So and the two requests here correspond to two um query jobs that go execute.
Um the first of which is a um what we call a a planonly query job. So this doesn't actually execute anything on the database, but it um goes through the whole um semantic planning process. So taking your model, turning that into a SQL query, checking to see if anything's in the cache and telling us what that query would look like.
So for example, um what happened here is it returned the SQL and and did the query. The second one here, which we actually kick off the other one first u because we want that one to um return the results as soon as possible. But uh the second one here is actually going to go through the exact same planning process.
So that plan happens twice, but then it actually goes and runs the query. So you can see down here we actually have this plan only false. Um this one runs um a little harder to see here, but there's a a query here that actually has results. Um so every time we run any query, you'll notice that there are two requests going, a plan and an execute.
Now, this doesn't happen when you run dashboards. Doesn't happen in, you know, suggestions and things like that. But, um, in order to make this UI look responsive, so we want to every time we make a change here, we update this the state here. So, it shows you, and this is happening pretty quick cuz my queries are pretty fast, but and the SQL.
So, we want to make sure that all that stuff is is kind of happening as soon as possible. You don't have to wait for the query results to come back in order to do that. Um, so it bugged me because we're doing the planning process twice. Now it's not it's not super expensive but as models get large and you know we have to combine layers with model extensions or whatnot um I wanted to see if we could avoid that double planning.
So what I have here on this branch is when I kick on click on things like user account we now only have a single um uh request here. Now, uh you'll note that the first one came on my local I'm connected to a slower system and a whole bunch of other stuff, but uh the first like result showed up and we actually got this update and it took a little bit longer.
Um so you can get a little bit better sense of what's happening for the query to actually execute. So the page pops in and then it executes. Similarly, if I click on state, you can see that this pops in here and the results came. Now that one happened a little bit faster between the two. It actually came from cache.
Um but um you know we we can kind of play with some of these things. I can pivot say by by gender right and update state here. Good results back. Similarly I can come in and say update state the state on the page results come in. So you can kind of see that that happening. And here I' you can see I actually have only run for four query executions.
The the sort of key change here is that instead of kicking off two independent um way requests and the jobs um there's actually only a single execution that happens and one request one job and instead of waiting for the query execution to complete to send the completion. So in the case of a plan the completion happens when the plan's done and when the query executes we send a completion when the query has completed.
Um what's happening is that we're sending uh a notification for both the plan completion and the query completion. Um and we're receiving both of those and then we're processing them effectively in order to um sort of get first with that same query query pipe um a single single sort of pass through the system. we get notifications of both of these things happening and this should allow us to be more efficient um not have to do double planning and sort of manage resources a little bit more effectively.
Uh definitely something that's still uh in progress and I'm still thinking through some of the best ways to structure the code in some of this in in in some of the places here but this is sort of a proof of concept to sort of see what happens and make it work. Mix.