Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
7e42bad
Link llvm dynamicly & implement memo popultaion
stewkk Apr 18, 2026
893e292
Impl search algorithm
stewkk Apr 19, 2026
8fe07e4
Refactoring
stewkk Apr 19, 2026
1495fe3
Refactoring
stewkk Apr 19, 2026
d2d6074
Implement RulesApplier
stewkk Apr 19, 2026
28cec90
Add deduptication in Memo
stewkk Apr 19, 2026
a62c354
Impl Memo population
stewkk Apr 19, 2026
c1657a7
Impl implementation rules handling in RulesApplier
stewkk Apr 19, 2026
2028669
Refactor
stewkk Apr 20, 2026
6f6c199
Update flake
stewkk Apr 20, 2026
8898de9
Add limit passing
stewkk Apr 22, 2026
3d99858
Implement branch & bound
stewkk Apr 23, 2026
ecdcca7
Add report wip
stewkk Apr 30, 2026
93ae089
wip
stewkk May 2, 2026
ea46c0e
Add pdf
stewkk May 4, 2026
ca605f4
Wip
stewkk May 5, 2026
030283d
Wip
stewkk May 6, 2026
8833c04
Wip
stewkk May 6, 2026
0683888
Done
stewkk May 6, 2026
470d60e
Fix
stewkk May 7, 2026
d27e517
Impl building optimal plan
stewkk May 9, 2026
095da0a
Impl plan serializer
stewkk May 9, 2026
af7fe0d
Impl execution of physical plan
stewkk May 11, 2026
5708c10
Add test
stewkk May 11, 2026
aadd497
Fix review issues
stewkk May 11, 2026
d164eaa
Fix
stewkk May 11, 2026
456171f
Fix
stewkk May 11, 2026
ca548b3
Add example
stewkk May 11, 2026
bb99b46
Fix
stewkk May 11, 2026
dae5cac
Fix
stewkk May 11, 2026
2795f12
Fix
stewkk May 11, 2026
3c571b9
Fix
stewkk May 11, 2026
38c53e9
Add todos
stewkk May 11, 2026
84bea1f
Refactor
stewkk May 11, 2026
847b183
Refactor, add debug logs, fix bug
stewkk May 11, 2026
0ede4e0
Fix
stewkk May 13, 2026
6c2d5f0
Add lazy loading of dataset
stewkk May 20, 2026
6b292d7
Add missing physical ops
stewkk May 20, 2026
d4df2e5
Implement converter
stewkk May 20, 2026
3157f2e
Add simple random query generator
stewkk May 20, 2026
6611f4f
Impl reachability check
stewkk May 21, 2026
89f826f
Add sort order property
stewkk May 22, 2026
51fdf3b
Add sort operator
stewkk May 22, 2026
c1e55d1
Impl sort by support in optimizer
stewkk May 22, 2026
25d1c21
Fix use after free
stewkk May 24, 2026
618a2c5
Refactor
stewkk May 24, 2026
bfff9d9
Refactor
stewkk May 24, 2026
8e827c3
Add ORDER BY support to parser
stewkk May 24, 2026
0c158bd
wip: needs review
stewkk May 25, 2026
0e99fd9
wip: hash join support, needs review
stewkk May 25, 2026
0ed6290
Impl fuzzing, fix bugs
stewkk May 27, 2026
0ead6f9
Add some rules
stewkk May 27, 2026
7400561
Add reachability fuzzer
stewkk May 27, 2026
30abea0
Fix bug in jit
stewkk May 29, 2026
2d00045
Add SBB benchmark
stewkk May 29, 2026
27111a9
Add strings support
stewkk May 29, 2026
950a8d5
Impl IN and BETWEEN support
stewkk May 29, 2026
fd68c68
Impl group by
stewkk May 29, 2026
03859f3
Add SBB benchmark
stewkk May 29, 2026
809b8c8
Support GROUP BY in fuzzers
stewkk May 30, 2026
0963a8d
Fix
stewkk May 30, 2026
1f2d8a8
Add dot visualization of plans
stewkk May 30, 2026
c5c9a32
Dump plans to disk
stewkk May 30, 2026
db36607
Output only on diffs
stewkk May 30, 2026
7fc9bb3
Fix
stewkk May 30, 2026
071018d
wip
stewkk May 30, 2026
5ab09a3
Update ssb-dbgen
stewkk May 30, 2026
031fe24
Add physical operator cost proof benchmarks
stewkk May 30, 2026
07e6a03
Plot benchmarks
stewkk May 30, 2026
cd2e6a8
Update coefficients
stewkk May 31, 2026
3ea373e
Fix
stewkk Jun 1, 2026
5d0e601
Add converted notebook
stewkk Jun 1, 2026
8bbd772
Add practice report
stewkk Jun 1, 2026
012be6f
Fix segfault
stewkk Jun 1, 2026
081074b
Add more benchmarks
stewkk Jun 1, 2026
53b7421
Add cost to runtime comparison on random queries
stewkk Jun 1, 2026
aa7cec6
Fix
stewkk Jun 1, 2026
2b63f14
Fix
stewkk Jun 2, 2026
299bcd1
Fix
stewkk Jun 2, 2026
3d4a815
Fix
stewkk Jun 2, 2026
7688ae2
Add report draft
stewkk Jun 5, 2026
1de9a98
Intro
stewkk Jun 6, 2026
e2bea7e
Refactor
stewkk Jun 6, 2026
dc80227
Refactor report
stewkk Jun 6, 2026
061024e
wip
stewkk Jun 6, 2026
90f30ec
wip
stewkk Jun 6, 2026
162619b
wip
stewkk Jun 6, 2026
6177f79
wip
stewkk Jun 7, 2026
f7c9fed
Done
stewkk Jun 7, 2026
4ebbc71
wip
stewkk Jun 7, 2026
e72864f
Done
stewkk Jun 7, 2026
d029f0a
Add naive plan cost
stewkk Jun 7, 2026
b482cd6
Add naive plan output
stewkk Jun 7, 2026
09eb82c
Add cost and cardinality to dot graph
stewkk Jun 7, 2026
c1d0eb7
Typo
stewkk Jun 7, 2026
a2ee42e
Index seek support in optimizer
stewkk Jun 7, 2026
0841199
Fix UB
stewkk Jun 7, 2026
16a4f45
Add MergeJoin
stewkk Jun 9, 2026
7cf088e
Add StreamAgg
stewkk Jun 9, 2026
c06be56
Update report and benchmarks
stewkk Jun 9, 2026
e06b6df
Update report
stewkk Jun 9, 2026
ea59a71
Update title
stewkk Jun 9, 2026
07935e1
Fix
stewkk Jun 9, 2026
815e14c
Fix
stewkk Jun 10, 2026
8483013
Done
stewkk Jun 10, 2026
d911f88
Implement remaining transformation rules and support constraints
stewkk Jun 10, 2026
eead31c
Fix
stewkk Jun 14, 2026
1c9a7b7
Fix
stewkk Jun 14, 2026
64b4713
Update
stewkk Jun 14, 2026
906f1ee
Fix
stewkk Jun 14, 2026
369a864
Fix
stewkk Jun 14, 2026
9b26cc5
Fix
stewkk Jun 14, 2026
455b649
Add stats collection
stewkk Jun 15, 2026
fcec0c0
More stats
stewkk Jun 15, 2026
b2a1810
Done?
stewkk Jun 15, 2026
fa35de0
Fix all
stewkk Jun 15, 2026
9d935f9
fix
stewkk Jun 15, 2026
32672f6
typos
stewkk Jun 15, 2026
b834120
typos
stewkk Jun 15, 2026
f861888
Add presentation
stewkk Jun 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ FlameGraph/
/perf.data.old
**/.auctex-auto/
**/build/
/.odbc/
**/__pycache__
/build-tsan/
/benchmarks/datasets/ssb/generated/
/benchmarks/datasets/ssb/raw/
/.plans/
/report/build-practice/
/report/build-vkr/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "research/datasets"]
path = research/datasets
url = git@github.com:ronaldbradford/data.git
[submodule "research/imdb-sqlserver"]
path = research/imdb-sqlserver
url = git@github.com:sqlsunday/imdb-to-sqlserver.git
[submodule "research/ssb-dbgen"]
path = research/ssb-dbgen
url = git@github.com:stewkk/ssb-dbgen.git
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ if (SANITIZE_THREADS)
add_link_options(-fsanitize=thread)
endif()

if(STEWKK_SQL_DEBUG)
add_definitions(-DSTEWKK_SQL_DEBUG)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ PARSER_SOURCE_DIR := $(CURRENT_DIR)/src/stewkk/sql/logic/parser
build:
cmake --build build -- -j 6

sanitize:
cmake --build build-sanitizers -- -j 8

codegen:
@antlr -Dlanguage=Cpp -visitor -o $(CODEGEN_DIR) -package stewkk::sql::codegen $(PARSER_SOURCE_DIR)/PostgreSQLParser.g4 $(PARSER_SOURCE_DIR)/PostgreSQLLexer.g4

.PHONY: codegen build
test-ssb-converter:
pytest benchmarks/datasets/ssb

dot:
dot -T png -O .plans/*.dot

.PHONY: codegen build sanitize test-ssb-converter
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(FetchGBenchmark)

add_executable(benchmarks main.cpp)
add_executable(benchmarks main.cpp operator_cost.cpp)
target_compile_features(benchmarks PRIVATE cxx_std_23)
set_target_properties(benchmarks PROPERTIES
CXX_STANDART 23
Expand Down
59 changes: 59 additions & 0 deletions benchmarks/datasets/ssb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Star Schema Benchmark data

This directory contains the schema and conversion tooling for Star Schema
Benchmark data. It does not download or build an SSB data generator; generate
the `.tbl` files with an external SSB dbgen-compatible tool first.

## Convert `.tbl` files

Expected input files:

- `lineorder.tbl`
- `customer.tbl`
- `supplier.tbl`
- `part.tbl`
- `date.tbl`

Convert them to the CSV format used by this project:

```sh
python3 benchmarks/datasets/ssb/convert_tbl_to_csv.py \
--input-dir /path/to/ssb/tbl \
--output-dir benchmarks/datasets/ssb/generated/sf1
```

The converter reads `schema.json` for table and column definitions. Output CSV
headers use `column:type`, for example `lo_orderkey:int`. String columns are
preserved as `string` values in the generated CSV.

Generated full-scale data should stay under `benchmarks/datasets/ssb/generated/`
or another ignored location.

## Queries

The standard 13 SSB query templates are in `queries/`. They are written in the
subset supported by this engine: explicit joins, table aliases, string
predicates, `BETWEEN`, list `IN`, `SUM`, `COUNT`, `GROUP BY`, and `ORDER BY`.

Run one query through the CLI:

```sh
./build/bin/sql --data-dir benchmarks/datasets/ssb/generated/sf1 \
< benchmarks/datasets/ssb/queries/q1.1.sql
```

Run SSB benchmarks after generating data:

```sh
SSB_DATA_DIR=benchmarks/datasets/ssb/generated/sf1 \
./build/bin/benchmarks --benchmark_filter='SSB/'
```

The JIT expression executor still rejects string and `IN` expressions, so the
SSB benchmark registrations currently use the interpreted expression executor.

## Test the converter

```sh
make test-ssb-converter
```
137 changes: 137 additions & 0 deletions benchmarks/datasets/ssb/convert_tbl_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env python3
"""Convert Star Schema Benchmark .tbl files to this project's CSV format."""

from __future__ import annotations

import argparse
import csv
import json
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable


SUPPORTED_TYPES = {"int", "string"}


@dataclass(frozen=True)
class Column:
name: str
type: str


@dataclass(frozen=True)
class Table:
name: str
columns: tuple[Column, ...]


class ConversionError(RuntimeError):
pass


def load_schema(path: Path) -> list[Table]:
with path.open(encoding="utf-8") as f:
raw = json.load(f)

tables = []
for table_raw in raw.get("tables", []):
columns = []
for column_raw in table_raw.get("columns", []):
column_type = column_raw["type"]
if column_type not in SUPPORTED_TYPES:
raise ConversionError(
f"{path}: unsupported type {column_type!r} in table {table_raw['name']}"
)
columns.append(Column(column_raw["name"], column_type))
if not columns:
raise ConversionError(f"{path}: table {table_raw.get('name')!r} has no columns")
tables.append(Table(table_raw["name"], tuple(columns)))

if not tables:
raise ConversionError(f"{path}: schema does not define any tables")
return tables


def parse_tbl_line(line: str) -> list[str]:
fields = line.rstrip("\r\n").split("|")
if fields and fields[-1] == "":
fields.pop()
return fields


def validate_row(table: Table, row: list[str], input_path: Path, line_no: int) -> None:
if len(row) != len(table.columns):
raise ConversionError(
f"{input_path}:{line_no}: expected {len(table.columns)} fields for "
f"{table.name}, got {len(row)}"
)

for value, column in zip(row, table.columns, strict=True):
if column.type == "int":
try:
int(value)
except ValueError as exc:
raise ConversionError(
f"{input_path}:{line_no}: {column.name} expects int, got {value!r}"
) from exc


def header(table: Table) -> list[str]:
return [f"{column.name}:{column.type}" for column in table.columns]


def convert_table(table: Table, input_dir: Path, output_dir: Path) -> int:
input_path = input_dir / f"{table.name}.tbl"
output_path = output_dir / f"{table.name}.csv"
if not input_path.exists():
raise ConversionError(f"missing input file: {input_path}")

rows = 0
with input_path.open(encoding="utf-8", newline="") as src, output_path.open(
"w", encoding="utf-8", newline=""
) as dst:
writer = csv.writer(dst, lineterminator="\n")
writer.writerow(header(table))
for line_no, line in enumerate(src, start=1):
row = parse_tbl_line(line)
validate_row(table, row, input_path, line_no)
writer.writerow(row)
rows += 1
return rows


def convert_all(schema_path: Path, input_dir: Path, output_dir: Path) -> dict[str, int]:
tables = load_schema(schema_path)
output_dir.mkdir(parents=True, exist_ok=True)
return {
table.name: convert_table(table, input_dir, output_dir)
for table in tables
}


def parse_args(argv: Iterable[str]) -> argparse.Namespace:
default_schema = Path(__file__).with_name("schema.json")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--input-dir", required=True, type=Path, help="Directory containing SSB .tbl files")
parser.add_argument("--output-dir", required=True, type=Path, help="Directory for generated CSV files")
parser.add_argument("--schema", default=default_schema, type=Path, help="Schema JSON path")
return parser.parse_args(argv)


def main(argv: Iterable[str] = sys.argv[1:]) -> int:
args = parse_args(argv)
try:
counts = convert_all(args.schema, args.input_dir, args.output_dir)
except ConversionError as exc:
print(f"error: {exc}", file=sys.stderr)
return 1

for table_name, rows in counts.items():
print(f"wrote {args.output_dir / (table_name + '.csv')} ({rows} rows)")
return 0


if __name__ == "__main__":
raise SystemExit(main())
3 changes: 3 additions & 0 deletions benchmarks/datasets/ssb/fixtures/expected_csv/customer.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
c_custkey:int,c_name:string,c_address:string,c_city:string,c_nation:string,c_region:string,c_phone:string,c_mktsegment:string
10,Customer#000000010,Addr 10,UNITED KI1,UNITED KINGDOM,EUROPE,10-111-111-1111,BUILDING
20,Customer#000000020,"Addr, 20",BRAZIL 1,BRAZIL,AMERICA,20-222-222-2222,AUTOMOBILE
3 changes: 3 additions & 0 deletions benchmarks/datasets/ssb/fixtures/expected_csv/date.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
d_datekey:int,d_date:string,d_dayofweek:string,d_month:string,d_year:int,d_yearmonthnum:int,d_yearmonth:string,d_daynuminweek:int,d_daynuminmonth:int,d_daynuminyear:int,d_monthnuminyear:int,d_weeknuminyear:int,d_sellingseason:string,d_lastdayinweekfl:int,d_lastdayinmonthfl:int,d_holidayfl:int,d_weekdayfl:int
19940101,"January 1, 1994",Saturday,January,1994,199401,Jan1994,6,1,1,1,1,Winter,0,0,1,0
19940102,"January 2, 1994",Sunday,January,1994,199401,Jan1994,7,2,2,1,1,Winter,1,0,0,0
3 changes: 3 additions & 0 deletions benchmarks/datasets/ssb/fixtures/expected_csv/lineorder.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lo_orderkey:int,lo_linenumber:int,lo_custkey:int,lo_partkey:int,lo_suppkey:int,lo_orderdate:int,lo_orderpriority:string,lo_shippriority:string,lo_quantity:int,lo_extendedprice:int,lo_ordtotalprice:int,lo_discount:int,lo_revenue:int,lo_supplycost:int,lo_tax:int,lo_commitdate:int,lo_shipmode:string
1,1,10,100,1000,19940101,1-URGENT,0,5,10000,12000,3,9700,6000,1,19940105,AIR
2,1,20,200,2000,19940102,2-HIGH,0,7,20000,23000,4,19200,12000,2,19940106,RAIL
3 changes: 3 additions & 0 deletions benchmarks/datasets/ssb/fixtures/expected_csv/part.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p_partkey:int,p_name:string,p_mfgr:string,p_category:string,p_brand:string,p_color:string,p_type:string,p_size:int,p_container:string
100,almond antique,MFGR#1,MFGR#11,MFGR#111,almond,STANDARD ANODIZED TIN,3,SM CASE
200,green burnished,MFGR#2,MFGR#22,MFGR#222,green,PROMO POLISHED STEEL,7,LG BOX
3 changes: 3 additions & 0 deletions benchmarks/datasets/ssb/fixtures/expected_csv/supplier.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
s_suppkey:int,s_name:string,s_address:string,s_city:string,s_nation:string,s_region:string,s_phone:string
1000,Supplier#000001000,Supplier Addr 1000,RUSSIA 1,RUSSIA,EUROPE,30-333-333-3333
2000,Supplier#000002000,Supplier Addr 2000,ARGENTINA1,ARGENTINA,AMERICA,40-444-444-4444
2 changes: 2 additions & 0 deletions benchmarks/datasets/ssb/fixtures/tbl/customer.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
10|Customer#000000010|Addr 10|UNITED KI1|UNITED KINGDOM|EUROPE|10-111-111-1111|BUILDING|
20|Customer#000000020|Addr, 20|BRAZIL 1|BRAZIL|AMERICA|20-222-222-2222|AUTOMOBILE|
2 changes: 2 additions & 0 deletions benchmarks/datasets/ssb/fixtures/tbl/date.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
19940101|January 1, 1994|Saturday|January|1994|199401|Jan1994|6|1|1|1|1|Winter|0|0|1|0|
19940102|January 2, 1994|Sunday|January|1994|199401|Jan1994|7|2|2|1|1|Winter|1|0|0|0|
2 changes: 2 additions & 0 deletions benchmarks/datasets/ssb/fixtures/tbl/lineorder.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1|1|10|100|1000|19940101|1-URGENT|0|5|10000|12000|3|9700|6000|1|19940105|AIR|
2|1|20|200|2000|19940102|2-HIGH|0|7|20000|23000|4|19200|12000|2|19940106|RAIL|
2 changes: 2 additions & 0 deletions benchmarks/datasets/ssb/fixtures/tbl/part.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
100|almond antique|MFGR#1|MFGR#11|MFGR#111|almond|STANDARD ANODIZED TIN|3|SM CASE|
200|green burnished|MFGR#2|MFGR#22|MFGR#222|green|PROMO POLISHED STEEL|7|LG BOX|
2 changes: 2 additions & 0 deletions benchmarks/datasets/ssb/fixtures/tbl/supplier.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1000|Supplier#000001000|Supplier Addr 1000|RUSSIA 1|RUSSIA|EUROPE|30-333-333-3333|
2000|Supplier#000002000|Supplier Addr 2000|ARGENTINA1|ARGENTINA|AMERICA|40-444-444-4444|
6 changes: 6 additions & 0 deletions benchmarks/datasets/ssb/queries/q1.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT SUM(lo.lo_extendedprice * lo.lo_discount) AS revenue
FROM lineorder AS lo
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
WHERE d.d_year = 1993
AND lo.lo_discount BETWEEN 1 AND 3
AND lo.lo_quantity < 25;
6 changes: 6 additions & 0 deletions benchmarks/datasets/ssb/queries/q1.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT SUM(lo.lo_extendedprice * lo.lo_discount) AS revenue
FROM lineorder AS lo
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
WHERE d.d_yearmonthnum = 199401
AND lo.lo_discount BETWEEN 4 AND 6
AND lo.lo_quantity BETWEEN 26 AND 35;
7 changes: 7 additions & 0 deletions benchmarks/datasets/ssb/queries/q1.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT SUM(lo.lo_extendedprice * lo.lo_discount) AS revenue
FROM lineorder AS lo
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
WHERE d.d_weeknuminyear = 6
AND d.d_year = 1994
AND lo.lo_discount BETWEEN 5 AND 7
AND lo.lo_quantity BETWEEN 26 AND 35;
9 changes: 9 additions & 0 deletions benchmarks/datasets/ssb/queries/q2.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT SUM(lo.lo_revenue) AS lo_revenue, d.d_year, p.p_brand
FROM lineorder AS lo
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
JOIN part AS p ON lo.lo_partkey = p.p_partkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
WHERE p.p_category = 'MFGR#12'
AND s.s_region = 'AMERICA'
GROUP BY d.d_year, p.p_brand
ORDER BY d.d_year, p.p_brand;
9 changes: 9 additions & 0 deletions benchmarks/datasets/ssb/queries/q2.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT SUM(lo.lo_revenue) AS lo_revenue, d.d_year, p.p_brand
FROM lineorder AS lo
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
JOIN part AS p ON lo.lo_partkey = p.p_partkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
WHERE p.p_brand BETWEEN 'MFGR#2221' AND 'MFGR#2228'
AND s.s_region = 'ASIA'
GROUP BY d.d_year, p.p_brand
ORDER BY d.d_year, p.p_brand;
9 changes: 9 additions & 0 deletions benchmarks/datasets/ssb/queries/q2.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT SUM(lo.lo_revenue) AS lo_revenue, d.d_year, p.p_brand
FROM lineorder AS lo
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
JOIN part AS p ON lo.lo_partkey = p.p_partkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
WHERE p.p_brand = 'MFGR#2221'
AND s.s_region = 'EUROPE'
GROUP BY d.d_year, p.p_brand
ORDER BY d.d_year, p.p_brand;
10 changes: 10 additions & 0 deletions benchmarks/datasets/ssb/queries/q3.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT c.c_nation, s.s_nation, d.d_year, SUM(lo.lo_revenue) AS lo_revenue
FROM lineorder AS lo
JOIN customer AS c ON lo.lo_custkey = c.c_custkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
WHERE c.c_region = 'ASIA'
AND s.s_region = 'ASIA'
AND d.d_year BETWEEN 1992 AND 1997
GROUP BY c.c_nation, s.s_nation, d.d_year
ORDER BY d.d_year, lo_revenue DESC;
10 changes: 10 additions & 0 deletions benchmarks/datasets/ssb/queries/q3.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT c.c_city, s.s_city, d.d_year, SUM(lo.lo_revenue) AS lo_revenue
FROM lineorder AS lo
JOIN customer AS c ON lo.lo_custkey = c.c_custkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
WHERE c.c_nation = 'UNITED STATES'
AND s.s_nation = 'UNITED STATES'
AND d.d_year BETWEEN 1992 AND 1997
GROUP BY c.c_city, s.s_city, d.d_year
ORDER BY d.d_year, lo_revenue DESC;
10 changes: 10 additions & 0 deletions benchmarks/datasets/ssb/queries/q3.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT c.c_city, s.s_city, d.d_year, SUM(lo.lo_revenue) AS lo_revenue
FROM lineorder AS lo
JOIN customer AS c ON lo.lo_custkey = c.c_custkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
WHERE c.c_city IN ('UNITED KI1', 'UNITED KI5')
AND s.s_city IN ('UNITED KI1', 'UNITED KI5')
AND d.d_year BETWEEN 1992 AND 1997
GROUP BY c.c_city, s.s_city, d.d_year
ORDER BY d.d_year, lo_revenue DESC;
10 changes: 10 additions & 0 deletions benchmarks/datasets/ssb/queries/q3.4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT c.c_city, s.s_city, d.d_year, SUM(lo.lo_revenue) AS lo_revenue
FROM lineorder AS lo
JOIN customer AS c ON lo.lo_custkey = c.c_custkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
WHERE c.c_city IN ('UNITED KI1', 'UNITED KI5')
AND s.s_city IN ('UNITED KI1', 'UNITED KI5')
AND d.d_yearmonth = 'Dec1997'
GROUP BY c.c_city, s.s_city, d.d_year
ORDER BY d.d_year, lo_revenue DESC;
11 changes: 11 additions & 0 deletions benchmarks/datasets/ssb/queries/q4.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT d.d_year, c.c_nation, SUM(lo.lo_revenue - lo.lo_supplycost) AS profit
FROM lineorder AS lo
JOIN date AS d ON lo.lo_orderdate = d.d_datekey
JOIN customer AS c ON lo.lo_custkey = c.c_custkey
JOIN supplier AS s ON lo.lo_suppkey = s.s_suppkey
JOIN part AS p ON lo.lo_partkey = p.p_partkey
WHERE c.c_region = 'AMERICA'
AND s.s_region = 'AMERICA'
AND p.p_mfgr IN ('MFGR#1', 'MFGR#2')
GROUP BY d.d_year, c.c_nation
ORDER BY d.d_year, c.c_nation;
Loading