‹ BackHN Continuity

Thread

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

702 points · 144 comments · polyphilz

  1. hamilyon2 · · focus · HN ↗
    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.

    1. yipinwong · · focus · HN ↗
      What if we use a hybrid model of using both query optimizer and LLM? Whichever produces better result, the database can use?

      - a question from someone with lack of DB depth, me.

      1. Sesse__ · · focus · HN ↗
        The immediate problem: How do you know which one is better without running them?
        1. scarmig · · focus · HN ↗

          [dead]

          1. Sesse__ · · focus · HN ↗
            This immediately halves your throughput.
            1. mattashii · · focus · HN ↗
              Only in the worst case when the plans are equivalent: If one plan is significantly faster, then it'll finish first, and the loser can get canceled before it finishes.
              1. 361994752 · · focus · HN ↗
                Good and bad plans can have orders of magnitude performance difference. The bad one can easily do enough damage cutting the performance in half before it is canceled.
        2. HighlandSpring · · focus · HN ↗
          Could you A/B at random, use that to collect data and eventually feed that back in to prefer A or B depending on the shape of the query?
          1. adrianN · · focus · HN ↗
            Customers love it when their queries sometimes run a lot longer.
          2. Sesse__ · · focus · HN ↗
            There are papers and Postgres projects that attempt this kind of learning-based optimization, with some success. None are in widespread use. (One part, but certainly not the entirety, of the problem is that it's not just A/B, it's an exponential number of options that all could seem close to each other.)
          3. mike_hearn · · focus · HN ↗
            You can and some databases can do this (e.g. Oracle).
        3. haroldl · · focus · HN ↗
          You create formulas to estimate the cost of running a given query plan. Use statistics collected about the tables (e.g. how many rows) to try to be accurate. The topic is "Cost Based Optimization".
          1. Sesse__ · · focus · HN ↗
            If you have formulas that actually match reality, what do you need the LLM for? An optimizer is perfectly capable of finding the optimal plan if it has a perfect estimator. In fact, if you could only estimate the number of rows in each subplan perfectly, you have as good as solved the problem already.
            1. locknitpicker · · focus · HN ↗
              > If you have formulas that actually match reality, what do you need the LLM for?

              That's the key question.

              I think LLMs allow people with no context or background or know-how to dive into projects and see some results being presented to them, but they don't have the context or skillset to tell what they see before them.

              This paves the way to people laying grand claims about achievements because of LLMs. Their claim is that LLMs know best primarily because LLMs knew more than them, not that the output is good or desirable.

            2. pbalau · · focus · HN ↗
              > If you have formulas that actually match reality, what do you need the LLM for?

              Because one could be in that state where they are trying to use a tech they know preciously little about to solve a problem they know nothing about.

              This reminds me of a request we got from our "AI Department": if you build us a proper shares market simulator, we will build you an awesome agent that can trade shares. They seemed quite confused when I pointed out that if we could build such a simulator, we wouldn't need them anymore.

          2. ants_a · · focus · HN ↗
            This is how the built in planner works already. It generates all possible plans and picks the one with the lowest cost. But calculating the cost is based on statistics and models, and these are wrong. Usually useful, but always wrong.
        4. yipinwong · · focus · HN ↗
          That's why I am a newbie for DB. I do not know how QO does that in the first place...
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.