4 ms·
"If you build something like that before". I think I can add that to the list of famous last words. ;) Please, excuse my sarcasm again. But, tell me what to do
by thesz 4y ago
"If you build something like that before". I think I can add that to the list of famous last words. ;)
Please, excuse my sarcasm again. But, tell me what to do if I didn't built something like this before? What if I built something like equality saturation engine, pseudoboolean optimization using SAT solver and/or beam search? Will it help me somehow?
You estimated code size at 4.5KLOC max. Given that C++ programmer delivers 20-25 debugged lines of code per hour in the long run (IBM's stats), it would take 225 hours of work. Given that PSP/TSP recommends planning for 4 hours-on-task per day, it will take 56 work days. My calculation suggests 2.5 work months to implement all that in the worst case of 4.5KLOC. Even the best case of 2.5KLOC would take a month and a half of work.
Yours' proposition is not a week's project. Not at all, you can't squeeze it that much.
Query planning is hard. Even if you try your best to avoid it.
And we have not even started talking about WHERE, GROUP BY and ORDER BY clauses' optimizations.
[1] shows the use of loop nest optimization combined with beam search. SQLite uses translation of joins into loop nests, and it transforms loop nests into a graph, the path in the graph represents a solution. The [1] shows simplified nesting graph that is linear, and in general it will be quadratic to the number of tables.
[1] https://www.sqlite.org/queryplanner-ng.html https://www.sqlite.org/queryplanner-ng.html
I really like that approach. This is exactly an equality saturation [2] (saturate loop nesting through loop nesting commutativity) with the beam search as a selection phase.
[2] https://rosstate.org/publications/eqsat/ https://rosstate.org/publications/eqsat/
I think that equality saturation with beam search is a week long project if you already have built something like that. The difference? It will work for arbitrary jons.
Of course I am making fun of your statements.
Equality saturation requires quite careful planning and will not work for couple of months, you will keep finding something that fails. Beam search is just as hard. You can encode optimal solution selection problem as a pseudoboolean optimization problem, which is more straightforward than beam search, and [2] shows that Pueblo is no slouch there.
This is not to say that query planning is easy when you do it my way. Query planning is hard. NP-hard, actually. Sometimes you can get away with a simpler less general solution, but it will bite you sooner than you expect.
- j-pb 4y agoC++ is probably the slowest programming language in terms of development speed there is, but even if it takes you 3 months to build something like that from scratch it'll still be an order of magnitude less time than building a clone of another SQL database. `WHERE, GROUP BY and ORDER BY` are relatively straightforward to tack on into the variable ordering. Having written a sat solver would kinda help you, because modern sat solving algorithms are fundamentally very similar to worst case optimal join algorithms. The query plan produced by combining binary joins is always going to be off by up to an exponential factor when compared to a WCO join. If you're fine throwing all that complexity onto your problem to generate sub-par query plans, be my guest.
- thesz 4y ago>The query plan produced by combining binary joins is always going to be off by up to an exponential factor when compared to a WCO join. Citation greatly needed. Why is it so?
- j-pb 4y agoThe intuition is that if your join is a triangle you might be forced to join every relation only to discover that the result is empty on the last join, which requires m^n intermediary results, where m is the size of the relations and n is the number of relations. A WCO join algorithm will figure out quite quickly that the output is empty and is in practice much more dependent on the actual output size, than the size of the input relations. See: https://www.cs.stanford.edu/people/chrismre/papers/paper49.Ngo.pdf https://www.cs.stanford.edu/people/chrismre/papers/paper49.N... https://justinjaffray.com/a-gentle-ish-introduction-to-worst-case-optimal-joins/ https://justinjaffray.com/a-gentle-ish-introduction-to-worst...
- thesz 4y agoThank you, second link of yours starts with the explanation of benefits expected, which is great. The difference is not exponential, if I may nitpick. It is sublinear in the case of the "triangles example" - WCO would produce O(n^(1.5)), binary join will produce O(n^2), the difference is O(n^(0.5)) or O(sqrt(n)). The difference is big, but not exponential.