mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 12:34:22 +01:00
After reading #1123, I wanted to see what optimizations I could do. Sqlite optimizes `count` aggregation for the following case: `SELECT count() FROM <tbl>`. This is so widely used, that they made an optimization just for it in the form of the `COUNT` opcode. This PR thus implements this optimization by creating the `COUNT` opcode, and checking in the select emitter if we the query is a Simple Count Query. If it is, we just emit the Opcode instead of going through a Rewind loop, saving on execution time. The screenshots below show a huge decrease in execution time. - **Main** <img width="383" alt="image" src="https://github.com/user- attachments/assets/99a9dec4-e7c5-41db-ba67-4eafa80dd2e6" /> - **Count Optimization** <img width="435" alt="image" src="https://github.com/user- attachments/assets/e93b3233-92e6-4736-aa60-b52b2477179f" /> Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #1443