697 points by polyphilz 5 days ago | 144 comments | View on ycombinator
refibrillator 5 days ago |
2001zhaozhao 5 days ago |
Infra: "Hmm, let's check... Well would you look at that, it seems like your LLM query planner usually works and produces fast queries, but this time when you changed a variable name to trigger query rebuild, it happened to hallucinate and miss an index, would you mind re-running the LLM a few times until you get a faster query?"
hamilyon2 5 days ago |
LLM is kind of blunt weapon to use here. I am waiting rather for alphago style neural net heuristic.
devsda 5 days ago |
Wouldn't admitting this invite trouble due to accusations of distillation flying around between closed and open models.
rand_r 4 days ago |
A big reason the initial plan isn't guaranteed to be optimal, even with all the right indexes, is that table statistics aren't perfect. For example, you might track a column's correlation (how closely the column's logical ordering matches its physical ordering in the heap), but that won't be broken down at a per value level. Postal code X might be very correlated, while postal code Y that is used in your query is completely uncorrelated.
The ideal solution is to pick one plan initially, and then update a temporary query-specific statistic model based on the data you actually read while executing the query. Then periodically re-evaluate if an alternative plan would be faster, switching to it in a way that doesn't throw away the current partial result.
Of course switching plans mid flight is very complicated, but Oracle and SQL server both support this feature, so hopefully it lands in Postgres at some point.
sgarland 5 days ago |
Nearly every time I’ve seen someone resorting to hints for a query, it’s because their statistics are incorrect. Adding hints is papering over the problem, and can backfire later if the data shape changes.
Someone 5 days ago |
> a tiny 4B model went from not being able to understand the harness it was wrapped in, to achieving a 1.81x geometric mean speedup and a summed latency decrease of 44.7% across a workload of join-heavy SQL queries
I can’t find it in the article (may have skimmed it too much), but I suspect they didn’t include those ~95 hours in the benchmark numbers.
I think all database vendors know their query optimizers could do much better if they could afford to spend lots of time to derive query plans.
⇒ this may be useful for some workloads, but even then, can you afford to spend hours every now and then to update your 4B model to ensure it still picks a good query plan?
BirdieNZ 5 days ago |
zacmps 4 days ago |
> Favorite settings The model regularly used enable_sort=off and random_page_cost=1.1
If random_page_cost wasn't set correctly for the default cases postgres's query planner can generate terrible plans (unless you're running on a spinning disk).
That could easily explain the difference by itself.
tancop 3 days ago |
This is the most important part. Most queries are either quick transactions that can run thousands of times per second, or complex but predictable scheduled analytics.
One off queries are pretty rare and optimizing for them instead of the common ones is a massive own goal almost every database is repeating. I don't think you need a LLM to beat Postgres.
undefined 5 days ago |
HackerThemAll 4 days ago |
Second. How would that LLM-based query optimizer work in a real-world 10,000 qps ERP system with very large shape of queries? I'm not saying it's useless, it just won't replace a real query planner soon. Latencies would skyrocket.
huahaiy 5 days ago |
[1] https://github.com/datalevin/datalevin/tree/master/benchmark...
nuc1e0n 3 days ago |
jerpint 5 days ago |
foota 5 days ago |
happyopossum 5 days ago |
Let’s talk when you are looking at double digit TB at a minimum.
anitil 5 days ago |
> As it turns out: enormously hard.
This exactly tracks me learning everything
perrygeo 5 days ago |
However, it misses the whole point of database query planning. You can't just ignore the planning time itself, as if the database query were a static entity to be optimized once at a leisurely pace.
The real constraint on live query planners is quite different: they must improve the combined time - planning + query - based on live database statistics. You can amortize the planning with prepared statements, but that too is fraught since optimal plans can change quite frequently and based on input parameters. "Live" and "faster than the queries themselves" are the hard requirements to be considered a viable database query planner. This project does neither.
rixed 5 days ago |
maxrumpf 5 days ago |
ashley95 5 days ago |
darepublic 5 days ago |
kingjimmy 5 days ago |
evaltoken 5 days ago |
fsmv 5 days ago |
mohd_rafay 4 days ago |
rtolkachev 4 days ago |
aitoolcrux 5 days ago |
itsmeduncan 4 days ago |
kevinbaiv 5 days ago |
saiyamshah1496 5 days ago |
tonetheman 5 days ago |
tobin1994 5 days ago |
basil_io 5 days ago |
poincareball 5 days ago |
trollied 5 days ago |
silverlinex 4 days ago |
coolThingsFirst 5 days ago |
Need 5 days just to go through it.
I would be cautious about over fitting, it’s tough to say if those query plans would really be more optimal than Postgres heuristics at scale and with a bit more realistic OLTP workloads.
In any case, such is life with profile guided optimization. Many of us appreciate how database workloads can drift over time and with scale.
Kudos to the author for getting their hands dirty and writing up their experiments.