Hacker News

New stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Royce on San Francisco(astralcodexten.com ↗)
    discuss
  2. Show HN: Make Art Not Apps(makeartnotapps.com ↗)
    discuss
  3. How Israel exports the technology of occupation around the world(universiteitleiden.nl ↗)
    discuss
  4. Destroying Humanity Is Against the Law(theatlantic.com ↗)
    discuss
  5. Apple's M6, M7 and M8 Chips Show How AI Is Reshaping the Company(twitter.com/markgurman ↗)
    discuss
  6. Elyx(elyx.design ↗)
    1comments
  7. Principles for a New Utopianism(deepmind.com ↗)
    discuss
  8. Trove of Never-Before-Seen Records Reveal How the Wealthiest Avoid Income Tax(propublica.org ↗)
    discuss
  9. Cookie converter and Claude session check I use(claudecookie.com ↗)
    discuss
  10. House Defies Automakers and Mandates AM Radio in New Cars(wsj.com ↗)
    2comments
  11. Netanyahu seeks to strip citizenship as threats to NAZA film directors intensify(theguardian.com ↗)
    discuss
  12. Nature Is Our Learning Environment(periodic.com ↗)
    discuss
  13. American, United, Southwest scale back schedules as fuel shock reshapes flying(reuters.com ↗)
    discuss
  14. Ms. Rachel on Gaza Controversy, YouTube Fame, and Her New Album(rollingstone.com ↗)
    discuss
  15. Open-1B: the first model you don't have to trust(gensyn.ai ↗)
    discuss
  16. OpenAI says CEO Altman will attend Trump's state dinner for Xi(reuters.com ↗)
    1comments
  17. Show HN: OpenCode Mentor - An anti-vibecoding, programming mentor configuration(github.com/davejpeters ↗)
    1comments
  18. Show HN: Hometowns – Map the area codes in your contacts list(benaduggan.github.io ↗)
    discuss
  19. The LLMs Yearn for the Spines(buttondown.com/hillelwayne ↗)
    discuss
  20. Show HN: unSnag – Display tasks you can do and graph task dependencies(unsnag.app ↗)
    discuss
  21. We're not ready for superpersistent AI(natesilver.net ↗)
    discuss
  22. Show HN: Vending Machine Lab – Build business, leave for 2 wks, see what breaks(vending-machine-lab.pages.dev ↗)
    discuss
  23. Reversing AIs tech job displacement(gist.github.com ↗)
    discuss
  24. Show HN: Interakt – open-source self-hosted search and AI chat for your website(github.com/alphasolutionsrepo ↗)
    discuss
  25. Gnome 51, "A Coruña"(gnome.org ↗)
    discuss
  26. Artemis II Launch 35mm High Speed Film (01.apr.2026)(nasa.gov ↗)
    discuss
  27. A 3D Rasterizer for Embedded Devices(github.com/cubecoders ↗)
    discuss
  28. Breaking the 1.58-bit Barrier for Ternary LLMs(arxiv.org ↗)
    discuss
  29. 2026 Small World in Motion Competition – Nikon Small World(nikonsmallworld.com ↗)
    discuss
  30. RustFS 1.0.0 GA: Production-Ready, Open Source, S3-Compatible Object Storage(rustfs.com ↗)
    discuss

Training a 4B model to produce 81% faster query plans than Postgres

211 pointsby 2h agorohanbansal.com
32 comments
2h agoHN ↗

But how will you know that the query plan actually does what your query asked for?

1h agoHN ↗

I imagine you can perform operations on query plans to transform them and determine equivalence?

1h agoHN ↗

`pg_hint_plan` has a debug log so you can verify Postgres actually used the hint or not! Used this during evaluations

1h agoHN ↗

I would like to think that pg_hint_plan is designed in such a way that any hint it accepts must be a valid plan for the query. I’m quite confident that schemes with this property that can also express high quality plans are possible and not even excessively complicated.

This is not to say that it’s possible to genetically verify that a proposed algorithm does what you want it to — that would be undecidable or NP-hard or co-NP-hard depending on how you formulate the question.

1h agoHN ↗

I wouldn't be very excited about adding a 4B param model to my database deployment, but using this kind of approach while testing an app to identify query plans where Postgres is leaving performance on the table seems valuable without much risk.

28m agoHN ↗

Given the approach from the article, you can commit the hints to git and run tests for verification. The model would be used during coding.

51m agoHN ↗

Because P!=NP (very probably IMHO) there's a huge class of problem for which LLMs are useful on the expensive and heuristic-y generation side because the verification is relatively inexpensive.

47m agoHN ↗

you'll have to prove equivalence through some Lean4 code perhaps? or some weird clause tree comparisons... good question indeed.

1h agoHN ↗

Aren't optimizations suppose to be deterministic?

1h agoHN ↗

They are not. Choice among several query plans depends on various summary statistics about the data, which might not be the most recent.

1h agoHN ↗

Including the input parameters.

It's not unusual for us to end up with bad query plans because the shape of our data can vary pretty greatly. In many cases, a Foo has 1 Bar. But in some cases, a Foo has a million Bars. That can cause the query optimizer to treat lookups on the bar table as if there are few elements there (causing a scan instead of a seek).

For the general case, the optimizer gets it right. However, the fringe case is one that causes the entire system to crash. It's a bit akin to how an insertion sort can be faster than quick sort when n is small. The optimizer might make a bad assumption about the size of n which makes it pick an expensive n lookup when log(n) is available (but slower for small n).

1h agoHN ↗

I'd like to contribute my amateur hour entry into this thread, although I did administer and develop mssql stuff for awhile.

sure optimizations based on stats, but the stats are the wildcard, in my experience query plans can change suddenly.

Queries are translated into plans according to statistics. However the transforms will be deterministic and should only change one valid plan to another. I could very easily see a neural network manipulate transforms the same way the current programming does, its just that the neural networks are by nature really nicely suitable because the "decisions" are based on training, and this training can be closed world type things like the ai assists that chess engines are now getting. Obviously ai still can't play chess but apparently its very good at ranking board positions just by developing that much statistical info because its training comes not from reading the web, but playing a gazzilian games against itself in a "closed" chess world of its own.

I'm thinking that the ai does "this legal transform of the query plan should be applied to this pattern of data (statistics, cardinality, etc)" simply because the ai encountered it in closed world training, much like the chess thing.

Just a theory tho feel free to correct!

19m agoHN ↗

Obviously ai still can't play chess

I believe you are wrong on that. Do you mean large language models can’t play chess?

1h agoHN ↗

I paid ~$800 to rent a 2x H100 SXM node from Lambda for ~95 hours, and ~$400 in OpenAI API fees to generate the Astra trajectory demonstrations.

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?

1h agoHN ↗

⇒ 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?

I think this would be likely comparable to a scheduled backup, so I think it would be an acceptable maintenance window. However, deterministic algorithms would likely beat re-training (or re-fine-tuning) the model. For example, one could analyze actual distributions or whatever (instead of assuming uniform), and then some plans would automatically be eliminated.

Imo a good thought experiment is to look at places that are hyper-optimized, like compilers. Would LLMs bring anything to the table (architecturally or performance-wise) to a piece of software that has been carefully crafted for decades? (Methinks no.)

24m agoHN ↗

The Postgres query planner has had to operate, for those same decades, in a much more realtime-sensitive and restricted environment than compilers. It can only draw its conclusions from summary statistics on tables in isolation, not on their relationships with each other (and even less so when filters are involved). For many cases this is fine! For many others it isn't.

1h agoHN ↗

Frontier intelligence is extremely powerful; the distillation I did off Astra trajectories is proof enough that large models are not going anywhere

Wouldn't admitting this invite trouble due to accusations of distillation flying around between closed and open models.

1h agoHN ↗

I don't think anybody's denying that small models are doing distillation, the issue at hand is frontier lab vs frontier lab when it comes to big models.

51m agoHN ↗

Frontier model trainers stole almost all the data they've trained on (the whole internet, all copyrighted).

It's very hard for them to claim the moral high ground here.

It's like stealing an apple from the British Colonial Empire.

46m agoHN ↗

Having the moral high ground matters less than having a big warchest of money to spend on lawyers.

40m agoHN ↗

Does it matter if they companies doing are not in the jurisdiction or even if they are, maybe the can't prove it?

21m agoHN ↗

They can't prove it but can force you to spend time and money to disprove it.

11m agoHN ↗

On the flip side, its important to know just how much we would be sacrificing if big frontier gets their way in convincing the courts that distillation is a bad thing

51m agoHN ↗

why is this write-up so long?

Need 5 days just to go through it.

47m agoHN ↗

They forgot to run a (same) model to optimize article for reading speed

37m agoHN ↗

Think of it like a paper. You wouldn't ask why a paper was so long.

Also you can now ask AI to summarise it for you and even probe with questions pertaining to your specific interests.

26m agoHN ↗

Why wouldn't you ask that? That's exactly why papers have supplementary material

43m agoHN ↗

Funny enough I was thinking about something very similar to this based on the Jev model posted yesterday.

27m agoHN ↗

“81% faster query plans than Postgres”…on an 8 GB dataset that fits entirely in memory, with shared_buffers constrained to a fraction of that, queries warmed before measuring, and read-only SELECTs.

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.

23m agoHN ↗

Optimal plan construction is math-heavy, algorithm-heavy and vary even by workload. There are options like creating just-in-time indexes, so solution space grows even faster than article presents. Sometimes it is the query planner which is the slow part of total execution time.

LLM is kind of blunt weapon to use here. I am waiting rather for alphago style neural net heuristic.