Urgent.News

What's breaking now, across thousands of outlets.

Tech

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

In 2015, researchers Leis et al. explored the question of query optimizer performance, only to find that they still have much to improve. Despite the extensive research in this area, query optimizers often leave much to be desired. The fact that a query optimizer needs to determine the optimal join ordering, an NP-hard problem, adds to the complexity.

However, language models excel at learning tasks with easily verifiable outputs, making them well-suited for this challenge. The key to improving query optimizer performance lies in reinforcing the behaviors that guide the model to produce faster query plans. The experiment conducted involved fine-tuning a small, open-weights model using supervised fine-tuning (SFT) and agentic reinforcement learning (RL) to generate Postgres query plans that outperform Postgres's default plans.

For instance, when querying the IMDb dataset for Japanese companies that released the most titles in the 2000s, the model was able to produce a query plan that surpassed Postgres's default plan. The main factors influencing the join ordering include selective predicates (filtering conditions in the WHERE clause) and the cardinality of the tables involved.

Postgres estimates cardinalities using statistics from the pg_statistic table, but this can lead to inaccuracies when the uniform distribution assumption fails. Overall, the results of this experiment demonstrate that a small, open-weights model can be trained to produce query plans that outperform Postgres's default plans, highlighting the potential of language models in optimizing database performance.

Written by urgent.news from Hacker News's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at rohanbansal.com →

More in Tech

More from Wednesday 16 September →