limbo/core/translate
Jussi Saurio c4548b51f1 Merge 'Optimization: lift common subexpressions from OR terms' from Jussi Saurio
```sql
-- This PR does effectively this transformation:

select
	sum(l_extendedprice* (1 - l_discount)) as revenue
from
	lineitem,
	part
where
	(
		p_partkey = l_partkey
		and p_brand = 'Brand#22'
		and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
		and l_quantity >= 8 and l_quantity <= 8 + 10
		and p_size between 1 and 5
		and l_shipmode in ('AIR', 'AIR REG')
		and l_shipinstruct = 'DELIVER IN PERSON'
	)
	or
	(
		p_partkey = l_partkey
		and p_brand = 'Brand#23'
		and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
		and l_quantity >= 10 and l_quantity <= 10 + 10
		and p_size between 1 and 10
		and l_shipmode in ('AIR', 'AIR REG')
		and l_shipinstruct = 'DELIVER IN PERSON'
	)
	or
	(
		p_partkey = l_partkey
		and p_brand = 'Brand#12'
		and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
		and l_quantity >= 24 and l_quantity <= 24 + 10
		and p_size between 1 and 15
		and l_shipmode in ('AIR', 'AIR REG')
		and l_shipinstruct = 'DELIVER IN PERSON'
	);

-- Same query with common conjuncts (ANDs) extracted:
select
	sum(l_extendedprice* (1 - l_discount)) as revenue
from
	lineitem,
	part
where
	p_partkey = l_partkey
	and l_shipmode in ('AIR', 'AIR REG')
	and l_shipinstruct = 'DELIVER IN PERSON'
	and (
		(
			p_brand = 'Brand#22'
			and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
			and l_quantity >= 8 and l_quantity <= 8 + 10
			and p_size between 1 and 5
		)
		or
		(
			p_brand = 'Brand#23'
			and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
			and l_quantity >= 10 and l_quantity <= 10 + 10
			and p_size between 1 and 10
		)
		or
		(
			p_brand = 'Brand#12'
			and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
			and l_quantity >= 24 and l_quantity <= 24 + 10
			and p_size between 1 and 15
		)
	);
```
This allows Limbo's optimizer to 1. recognize `p_partkey=l_partkey` as
an index constraint on `part`, and 2. filter out `lineitem` rows before
joining. With this optimization, Limbo completes TPC-H `19.sql` nearly
as fast as SQLite on my machine. Without it, Limbo takes forever.
This branch: `939ms`
Main: `uh, i started running it a few minutes ago and it hasnt finished,
and i dont feel like waiting i guess`

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1520
2025-05-20 14:33:49 +03:00
..
optimizer Merge 'Optimization: lift common subexpressions from OR terms' from Jussi Saurio 2025-05-20 14:33:49 +03:00
aggregation.rs Support distinct aggregates in GROUP BY 2025-05-17 15:33:55 +03:00
collate.rs Correct Rtrim 2025-05-19 15:22:15 -03:00
delete.rs implement IdxDelete 2025-04-24 16:23:34 +02:00
emitter.rs Merge 'refactor: replace Operation::Subquery with Table::FromClauseSubquery' from Jussi Saurio 2025-05-20 14:31:42 +03:00
expr.rs Merge 'Optimization: lift common subexpressions from OR terms' from Jussi Saurio 2025-05-20 14:33:49 +03:00
group_by.rs Merge 'Add support for DISTINCT aggregate functions' from Jussi Saurio 2025-05-20 13:58:57 +03:00
index.rs Add collation column to Index struct 2025-05-20 12:52:54 +03:00
insert.rs modify explain for MakeRecord to show index name 2025-05-14 13:30:39 -03:00
main_loop.rs Merge 'refactor: replace Operation::Subquery with Table::FromClauseSubquery' from Jussi Saurio 2025-05-20 14:31:42 +03:00
mod.rs Create CollationSeq enum and functions. Move strum to workspace dependency to avoid version mismatch with Parser 2025-05-19 15:22:14 -03:00
order_by.rs refactor BtreeCursor and Sorter to accept Vec of collations 2025-05-19 15:22:55 -03:00
plan.rs Merge 'refactor: replace Operation::Subquery with Table::FromClauseSubquery' from Jussi Saurio 2025-05-20 14:31:42 +03:00
planner.rs Merge 'Add support for DISTINCT aggregate functions' from Jussi Saurio 2025-05-20 13:58:57 +03:00
pragma.rs Eliminate a superfluous read transaction when doing PRAGMA user_version 2025-05-03 10:48:27 +03:00
result_row.rs GROUP BY: refactor logic to support cases where no sorting is needed 2025-05-08 12:39:26 +03:00
schema.rs Replace Operation::Subquery with Table::FromClauseSubquery 2025-05-20 12:56:30 +03:00
select.rs Merge 'refactor: replace Operation::Subquery with Table::FromClauseSubquery' from Jussi Saurio 2025-05-20 14:31:42 +03:00
subquery.rs Replace Operation::Subquery with Table::FromClauseSubquery 2025-05-20 12:56:30 +03:00
transaction.rs Fix existing resolve_label() calls to work with new system 2025-04-24 11:05:21 +03:00
update.rs feat: initial implementation of ALTER TABLE 2025-05-08 09:24:56 -03:00