PostBOUND 0.23.0__tar.gz → 0.23.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {postbound-0.23.0 → postbound-0.23.2}/PKG-INFO +2 -2
- {postbound-0.23.0 → postbound-0.23.2}/PostBOUND.egg-info/PKG-INFO +2 -2
- {postbound-0.23.0 → postbound-0.23.2}/PostBOUND.egg-info/requires.txt +1 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/_core.py +17 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/_hints.py +23 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/_pipelines.py +80 -14
- {postbound-0.23.0 → postbound-0.23.2}/postbound/_qep.py +21 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/_stages.py +14 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/bench.py +4 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/db/_cache.py +16 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/db/_db.py +41 -7
- {postbound-0.23.0 → postbound-0.23.2}/postbound/db/_stats.py +8 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/duckdb/_duckdb.py +122 -54
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/__init__.pyi +2 -5
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/_cardinalities.py +190 -4
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/_dynprog.py +11 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/_native.py +15 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/_randomized.py +10 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/parser.py +8 -5
- {postbound-0.23.0 → postbound-0.23.2}/postbound/postgres/_config.py +3 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/postgres/_explain.py +12 -2
- {postbound-0.23.0 → postbound-0.23.2}/postbound/postgres/_pg.py +42 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/qal/_formatter.py +4 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/qal/_qal.py +405 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/relalg.py +150 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/train/_train.py +9 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/transform.py +56 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/collections.py +11 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/dicts.py +10 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/jsonize.py +2 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/misc.py +6 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/num.py +75 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/nx.py +5 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/proc.py +3 -1
- {postbound-0.23.0 → postbound-0.23.2}/postbound/validation.py +41 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/workloads.py +6 -1
- {postbound-0.23.0 → postbound-0.23.2}/pyproject.toml +5 -2
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_benchmarking.py +19 -0
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_core.py +2 -0
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_duckdb.py +254 -3
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_postgres.py +6 -0
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_qal.py +31 -1
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_util.py +5 -0
- {postbound-0.23.0 → postbound-0.23.2}/LICENSE.txt +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/PostBOUND.egg-info/SOURCES.txt +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/PostBOUND.egg-info/dependency_links.txt +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/PostBOUND.egg-info/top_level.txt +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/README.md +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/__init__.pyi +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/_base.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/_ipython.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/db/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/duckdb/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/_enumeration.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/opt/_helpers.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/postgres/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/postgres/_ctl.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/qal/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/train/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/__init__.pyi +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/_df.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/_errors.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/logging.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/stats.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/system.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/util/typing.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/vis/__init__.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/vis/__init__.pyi +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/vis/fdl.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/vis/graphs.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/vis/optimizer.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/vis/plots.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/postbound/vis/trees.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/setup.cfg +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_docs.py +0 -0
- {postbound-0.23.0 → postbound-0.23.2}/tests/test_relalg.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PostBOUND
|
|
3
|
-
Version: 0.23.
|
|
3
|
+
Version: 0.23.2
|
|
4
4
|
Summary: PostBOUND is a research framework to prototype and benchmark database query optimizers
|
|
5
5
|
Author-email: Rico Bergmann <rico.bergmann1@tu-dresden.de>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -21,7 +21,7 @@ Requires-Dist: numpy~=2.3
|
|
|
21
21
|
Requires-Dist: pandas~=2.3
|
|
22
22
|
Requires-Dist: pglast~=7.10
|
|
23
23
|
Requires-Dist: psycopg[binary]~=3.2
|
|
24
|
-
Requires-Dist: quacklab
|
|
24
|
+
Requires-Dist: quacklab==2.0.2
|
|
25
25
|
Requires-Dist: tqdm~=4.67
|
|
26
26
|
Provides-Extra: vis
|
|
27
27
|
Requires-Dist: matplotlib~=3.10; extra == "vis"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PostBOUND
|
|
3
|
-
Version: 0.23.
|
|
3
|
+
Version: 0.23.2
|
|
4
4
|
Summary: PostBOUND is a research framework to prototype and benchmark database query optimizers
|
|
5
5
|
Author-email: Rico Bergmann <rico.bergmann1@tu-dresden.de>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -21,7 +21,7 @@ Requires-Dist: numpy~=2.3
|
|
|
21
21
|
Requires-Dist: pandas~=2.3
|
|
22
22
|
Requires-Dist: pglast~=7.10
|
|
23
23
|
Requires-Dist: psycopg[binary]~=3.2
|
|
24
|
-
Requires-Dist: quacklab
|
|
24
|
+
Requires-Dist: quacklab==2.0.2
|
|
25
25
|
Requires-Dist: tqdm~=4.67
|
|
26
26
|
Provides-Extra: vis
|
|
27
27
|
Requires-Dist: matplotlib~=3.10; extra == "vis"
|
|
@@ -13,6 +13,7 @@ from typing import (
|
|
|
13
13
|
TypeGuard,
|
|
14
14
|
TypeVar,
|
|
15
15
|
overload,
|
|
16
|
+
override,
|
|
16
17
|
)
|
|
17
18
|
|
|
18
19
|
from .util._errors import StateError
|
|
@@ -396,6 +397,7 @@ class Cardinality(Number):
|
|
|
396
397
|
return complex(math.inf)
|
|
397
398
|
return complex(float(self.value))
|
|
398
399
|
|
|
400
|
+
@override
|
|
399
401
|
def __eq__(self, other: object) -> bool:
|
|
400
402
|
match other:
|
|
401
403
|
case Cardinality():
|
|
@@ -419,13 +421,16 @@ class Cardinality(Number):
|
|
|
419
421
|
|
|
420
422
|
return NotImplemented
|
|
421
423
|
|
|
424
|
+
@override
|
|
422
425
|
def __hash__(self) -> int:
|
|
423
426
|
# There is no need to hash _valid, since it is directly derived from _nan and _inf
|
|
424
427
|
return hash(self.raw_value)
|
|
425
428
|
|
|
429
|
+
@override
|
|
426
430
|
def __repr__(self) -> str:
|
|
427
431
|
return str(self)
|
|
428
432
|
|
|
433
|
+
@override
|
|
429
434
|
def __str__(self) -> str:
|
|
430
435
|
if self._nan:
|
|
431
436
|
return "NaN"
|
|
@@ -1059,9 +1064,11 @@ class TableReference:
|
|
|
1059
1064
|
return NotImplemented
|
|
1060
1065
|
return self._normalized_identifier < other._normalized_identifier
|
|
1061
1066
|
|
|
1067
|
+
@override
|
|
1062
1068
|
def __hash__(self) -> int:
|
|
1063
1069
|
return self._hash_val
|
|
1064
1070
|
|
|
1071
|
+
@override
|
|
1065
1072
|
def __eq__(self, other: object) -> bool:
|
|
1066
1073
|
return (
|
|
1067
1074
|
isinstance(other, type(self))
|
|
@@ -1071,12 +1078,14 @@ class TableReference:
|
|
|
1071
1078
|
and self._normalized_catalog == other._normalized_catalog
|
|
1072
1079
|
)
|
|
1073
1080
|
|
|
1081
|
+
@override
|
|
1074
1082
|
def __repr__(self) -> str:
|
|
1075
1083
|
return (
|
|
1076
1084
|
f"TableReference(full_name='{self.full_name}', alias='{self.alias}', "
|
|
1077
1085
|
f"virtual={self.virtual}, schema='{self.schema}', catalog='{self.catalog}')"
|
|
1078
1086
|
)
|
|
1079
1087
|
|
|
1088
|
+
@override
|
|
1080
1089
|
def __str__(self) -> str:
|
|
1081
1090
|
return self._sql_repr
|
|
1082
1091
|
|
|
@@ -1347,9 +1356,11 @@ class ColumnReference:
|
|
|
1347
1356
|
return False
|
|
1348
1357
|
return self.table < other.table
|
|
1349
1358
|
|
|
1359
|
+
@override
|
|
1350
1360
|
def __hash__(self) -> int:
|
|
1351
1361
|
return self._hash_val
|
|
1352
1362
|
|
|
1363
|
+
@override
|
|
1353
1364
|
def __eq__(self, other: object) -> bool:
|
|
1354
1365
|
return (
|
|
1355
1366
|
isinstance(other, (ColumnReference, BoundColumnReference))
|
|
@@ -1364,12 +1375,15 @@ class ColumnReference:
|
|
|
1364
1375
|
tab = copy.deepcopy(self.table, memo)
|
|
1365
1376
|
return ColumnReference(str(self.name), tab)
|
|
1366
1377
|
|
|
1378
|
+
@override
|
|
1367
1379
|
def __reduce__(self) -> tuple:
|
|
1368
1380
|
return (self.__class__, (self._name, self._table))
|
|
1369
1381
|
|
|
1382
|
+
@override
|
|
1370
1383
|
def __repr__(self) -> str:
|
|
1371
1384
|
return f"ColumnReference(name='{self.name}', table={self.table!r})"
|
|
1372
1385
|
|
|
1386
|
+
@override
|
|
1373
1387
|
def __str__(self) -> str:
|
|
1374
1388
|
return self._sql_repr
|
|
1375
1389
|
|
|
@@ -1388,13 +1402,16 @@ class BoundColumnReference(ColumnReference):
|
|
|
1388
1402
|
__match_args__ = ("name", "table")
|
|
1389
1403
|
|
|
1390
1404
|
@property
|
|
1405
|
+
@override
|
|
1391
1406
|
def table(self) -> TableReference:
|
|
1392
1407
|
"""Get the table to which this column belongs. This is guaranteed to be set and will never be *None*."""
|
|
1393
1408
|
return self._table # type: ignore
|
|
1394
1409
|
|
|
1410
|
+
@override
|
|
1395
1411
|
def is_bound(self) -> bool:
|
|
1396
1412
|
return True
|
|
1397
1413
|
|
|
1414
|
+
@override
|
|
1398
1415
|
def drop_table_alias(self) -> BoundColumnReference:
|
|
1399
1416
|
return super().drop_table_alias() # type: ignore
|
|
1400
1417
|
|
|
@@ -4,7 +4,7 @@ import math
|
|
|
4
4
|
import warnings
|
|
5
5
|
from collections.abc import Collection, Container, Iterable, Sequence
|
|
6
6
|
from enum import Enum
|
|
7
|
-
from typing import Any, Literal, Self, assert_never
|
|
7
|
+
from typing import Any, Literal, Self, assert_never, override
|
|
8
8
|
|
|
9
9
|
from . import util
|
|
10
10
|
from ._base import T
|
|
@@ -543,6 +543,7 @@ class PhysicalOperatorAssignment:
|
|
|
543
543
|
else:
|
|
544
544
|
return None
|
|
545
545
|
|
|
546
|
+
@override
|
|
546
547
|
def __hash__(self) -> int:
|
|
547
548
|
return hash(
|
|
548
549
|
(
|
|
@@ -552,6 +553,7 @@ class PhysicalOperatorAssignment:
|
|
|
552
553
|
)
|
|
553
554
|
)
|
|
554
555
|
|
|
556
|
+
@override
|
|
555
557
|
def __eq__(self, other: object) -> bool:
|
|
556
558
|
return (
|
|
557
559
|
isinstance(other, type(self))
|
|
@@ -560,9 +562,11 @@ class PhysicalOperatorAssignment:
|
|
|
560
562
|
and self.join_operators == other.join_operators
|
|
561
563
|
)
|
|
562
564
|
|
|
565
|
+
@override
|
|
563
566
|
def __repr__(self) -> str:
|
|
564
567
|
return str(self)
|
|
565
568
|
|
|
569
|
+
@override
|
|
566
570
|
def __str__(self) -> str:
|
|
567
571
|
global_str = ", ".join(f"{op.value}: {enabled}" for op, enabled in self.global_settings.items())
|
|
568
572
|
|
|
@@ -824,9 +828,11 @@ class PlanParameterization:
|
|
|
824
828
|
],
|
|
825
829
|
}
|
|
826
830
|
|
|
831
|
+
@override
|
|
827
832
|
def __repr__(self) -> str:
|
|
828
833
|
return str(self)
|
|
829
834
|
|
|
835
|
+
@override
|
|
830
836
|
def __str__(self) -> str:
|
|
831
837
|
return (
|
|
832
838
|
f"PlanParams(cards={self.cardinalities}, "
|
|
@@ -914,9 +920,11 @@ class ScanOperatorAssignment:
|
|
|
914
920
|
"parallel_workers": self.parallel_workers,
|
|
915
921
|
}
|
|
916
922
|
|
|
923
|
+
@override
|
|
917
924
|
def __hash__(self) -> int:
|
|
918
925
|
return self._hash_val
|
|
919
926
|
|
|
927
|
+
@override
|
|
920
928
|
def __eq__(self, other: object) -> bool:
|
|
921
929
|
return (
|
|
922
930
|
isinstance(other, type(self))
|
|
@@ -925,9 +933,11 @@ class ScanOperatorAssignment:
|
|
|
925
933
|
and self.parallel_workers == other.parallel_workers
|
|
926
934
|
)
|
|
927
935
|
|
|
936
|
+
@override
|
|
928
937
|
def __repr__(self) -> str:
|
|
929
938
|
return str(self)
|
|
930
939
|
|
|
940
|
+
@override
|
|
931
941
|
def __str__(self) -> str:
|
|
932
942
|
return f"{self.operator.value}({self.table})"
|
|
933
943
|
|
|
@@ -1052,9 +1062,11 @@ class JoinOperatorAssignment:
|
|
|
1052
1062
|
"parallel_workers": self.parallel_workers,
|
|
1053
1063
|
}
|
|
1054
1064
|
|
|
1065
|
+
@override
|
|
1055
1066
|
def __hash__(self) -> int:
|
|
1056
1067
|
return self._hash_val
|
|
1057
1068
|
|
|
1069
|
+
@override
|
|
1058
1070
|
def __eq__(self, other: object) -> bool:
|
|
1059
1071
|
return (
|
|
1060
1072
|
isinstance(other, type(self))
|
|
@@ -1063,9 +1075,11 @@ class JoinOperatorAssignment:
|
|
|
1063
1075
|
and self._parallel_workers == other._parallel_workers
|
|
1064
1076
|
)
|
|
1065
1077
|
|
|
1078
|
+
@override
|
|
1066
1079
|
def __repr__(self) -> str:
|
|
1067
1080
|
return str(self)
|
|
1068
1081
|
|
|
1082
|
+
@override
|
|
1069
1083
|
def __str__(self) -> str:
|
|
1070
1084
|
join_str = ", ".join(str(tab) for tab in self.join)
|
|
1071
1085
|
return f"{self.operator.value}({join_str})"
|
|
@@ -1141,9 +1155,11 @@ class DirectionalJoinOperatorAssignment(JoinOperatorAssignment):
|
|
|
1141
1155
|
"""
|
|
1142
1156
|
return self._outer
|
|
1143
1157
|
|
|
1158
|
+
@override
|
|
1144
1159
|
def is_directional(self) -> bool:
|
|
1145
1160
|
return True
|
|
1146
1161
|
|
|
1162
|
+
@override
|
|
1147
1163
|
def __json__(self) -> jsondict:
|
|
1148
1164
|
return {
|
|
1149
1165
|
"directional": True,
|
|
@@ -1155,6 +1171,7 @@ class DirectionalJoinOperatorAssignment(JoinOperatorAssignment):
|
|
|
1155
1171
|
|
|
1156
1172
|
__hash__ = JoinOperatorAssignment.__hash__
|
|
1157
1173
|
|
|
1174
|
+
@override
|
|
1158
1175
|
def __eq__(self, other: object) -> bool:
|
|
1159
1176
|
return (
|
|
1160
1177
|
isinstance(other, type(self))
|
|
@@ -1586,15 +1603,18 @@ class JoinTree[JoinTreeAnnotation](Container[TableReference]):
|
|
|
1586
1603
|
def __bool__(self) -> bool:
|
|
1587
1604
|
return not self.is_empty()
|
|
1588
1605
|
|
|
1606
|
+
@override
|
|
1589
1607
|
def __contains__(self, item: TableReference) -> bool:
|
|
1590
1608
|
return self.lookup(item) is not None
|
|
1591
1609
|
|
|
1592
1610
|
def __len__(self) -> int:
|
|
1593
1611
|
return len(self.tables())
|
|
1594
1612
|
|
|
1613
|
+
@override
|
|
1595
1614
|
def __hash__(self) -> int:
|
|
1596
1615
|
return self._hash_val
|
|
1597
1616
|
|
|
1617
|
+
@override
|
|
1598
1618
|
def __eq__(self, other: object) -> bool:
|
|
1599
1619
|
return (
|
|
1600
1620
|
isinstance(other, type(self))
|
|
@@ -1603,9 +1623,11 @@ class JoinTree[JoinTreeAnnotation](Container[TableReference]):
|
|
|
1603
1623
|
and self._inner == other._inner
|
|
1604
1624
|
)
|
|
1605
1625
|
|
|
1626
|
+
@override
|
|
1606
1627
|
def __repr__(self) -> str:
|
|
1607
1628
|
return str(self)
|
|
1608
1629
|
|
|
1630
|
+
@override
|
|
1609
1631
|
def __str__(self):
|
|
1610
1632
|
if self.is_scan():
|
|
1611
1633
|
assert self._table is not None
|
|
@@ -9,7 +9,7 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import abc
|
|
11
11
|
from collections.abc import Collection, Mapping
|
|
12
|
-
from typing import Protocol, Self
|
|
12
|
+
from typing import Protocol, Self, override
|
|
13
13
|
|
|
14
14
|
from ._core import TimeMs
|
|
15
15
|
from ._hints import PhysicalOperatorAssignment, PlanParameterization
|
|
@@ -414,6 +414,7 @@ class IntegratedOptimizationPipeline(OptimizationPipeline):
|
|
|
414
414
|
self._build = True
|
|
415
415
|
return self
|
|
416
416
|
|
|
417
|
+
@override
|
|
417
418
|
def query_execution_plan(self, query: SqlQuery) -> QueryPlan:
|
|
418
419
|
if not self._build:
|
|
419
420
|
raise StateError(
|
|
@@ -428,14 +429,17 @@ class IntegratedOptimizationPipeline(OptimizationPipeline):
|
|
|
428
429
|
physical_qep = self.optimization_algorithm.optimize_query(query)
|
|
429
430
|
return physical_qep
|
|
430
431
|
|
|
432
|
+
@override
|
|
431
433
|
def stages(self) -> list[OptimizationStage]:
|
|
432
434
|
if self.optimization_algorithm is None:
|
|
433
435
|
return []
|
|
434
436
|
return [self.optimization_algorithm]
|
|
435
437
|
|
|
438
|
+
@override
|
|
436
439
|
def target_database(self) -> Database:
|
|
437
440
|
return self._target_db
|
|
438
441
|
|
|
442
|
+
@override
|
|
439
443
|
def describe(self) -> jsondict:
|
|
440
444
|
algorithm_description = (
|
|
441
445
|
self._optimization_algorithm.describe() if self._optimization_algorithm is not None else "no_algorithm"
|
|
@@ -446,9 +450,11 @@ class IntegratedOptimizationPipeline(OptimizationPipeline):
|
|
|
446
450
|
"optimization_algorithm": algorithm_description,
|
|
447
451
|
}
|
|
448
452
|
|
|
453
|
+
@override
|
|
449
454
|
def __repr__(self) -> str:
|
|
450
455
|
return str(self)
|
|
451
456
|
|
|
457
|
+
@override
|
|
452
458
|
def __str__(self) -> str:
|
|
453
459
|
return f"IntegratedOptimization [{self._optimization_algorithm}]"
|
|
454
460
|
|
|
@@ -460,7 +466,20 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
460
466
|
quantifies how expensive specific access paths for the intermediates are, and an enumerator that generates the
|
|
461
467
|
intermediates in the first place.
|
|
462
468
|
|
|
463
|
-
To configure the pipeline, specific strategies for each of the three components have to be assigned.
|
|
469
|
+
To configure the pipeline, specific strategies for each of the three components have to be assigned. If individual
|
|
470
|
+
components have not been configured, defaults based on the optimizer of the target database system are used.
|
|
471
|
+
Note that these defaults are probably not what you want: the default cost model requests cost estimates from the
|
|
472
|
+
target database. While this is a fine default, it introduces a significant overhead to the estimation process,
|
|
473
|
+
since the enumerator typically explores a large number of candidate plans. The default plan enumerator is a simple
|
|
474
|
+
dynamic programming-style algorithm. This algorithm cannot capture the specifics of the target database system and
|
|
475
|
+
can produce very different plans than the native optimizer. To ease this situation somewhat, we use a special
|
|
476
|
+
enumerator if the target database is Postgres. While this enumerator was implemented to closely mirror the
|
|
477
|
+
optimization process of Postgres, it is not a 1:1 replacement and the fundamental limitation is still there.
|
|
478
|
+
Lastly, the default cardinality estimator requests cardinality estimates from the target database, which is a fine
|
|
479
|
+
default.
|
|
480
|
+
|
|
481
|
+
If only a cardinality estimator is set up and both cost model and plan enumerator are left at their defaults,
|
|
482
|
+
the optimization process effectively degenerates to the same logic that the `MultiStageOptimizationPipeline` uses.
|
|
464
483
|
|
|
465
484
|
Parameters
|
|
466
485
|
----------
|
|
@@ -486,9 +505,14 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
486
505
|
else:
|
|
487
506
|
self._plan_enumerator = DynamicProgrammingEnumerator(target_db=target_db)
|
|
488
507
|
|
|
508
|
+
self._default_card_est = True
|
|
509
|
+
self._default_cost_model = True
|
|
510
|
+
self._default_plan_enum = True
|
|
511
|
+
|
|
489
512
|
self._support_check = EmptyPreCheck()
|
|
490
513
|
self._build = False
|
|
491
514
|
|
|
515
|
+
@override
|
|
492
516
|
def target_database(self) -> Database:
|
|
493
517
|
return self._target_db
|
|
494
518
|
|
|
@@ -507,8 +531,9 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
507
531
|
self
|
|
508
532
|
The current pipeline to allow for easy method-chaining.
|
|
509
533
|
"""
|
|
510
|
-
self._build = False
|
|
511
534
|
self._card_est = estimator
|
|
535
|
+
self._build = False
|
|
536
|
+
self._default_card_est = False
|
|
512
537
|
return self
|
|
513
538
|
|
|
514
539
|
def setup_cost_model(self, cost_model: CostModel) -> Self:
|
|
@@ -526,8 +551,9 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
526
551
|
self
|
|
527
552
|
The current pipeline to allow for easy method-chaining.
|
|
528
553
|
"""
|
|
529
|
-
self._build = False
|
|
530
554
|
self._cost_model = cost_model
|
|
555
|
+
self._build = False
|
|
556
|
+
self._default_cost_model = False
|
|
531
557
|
return self
|
|
532
558
|
|
|
533
559
|
def setup_plan_enumerator(self, plan_enumerator: PlanEnumerator) -> Self:
|
|
@@ -545,8 +571,9 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
545
571
|
self
|
|
546
572
|
The current pipeline to allow for easy method-chaining.
|
|
547
573
|
"""
|
|
548
|
-
self._build = False
|
|
549
574
|
self._plan_enumerator = plan_enumerator
|
|
575
|
+
self._build = False
|
|
576
|
+
self._default_plan_enum = False
|
|
550
577
|
return self
|
|
551
578
|
|
|
552
579
|
def use(self, component: PlanEnumerator | CostModel | CardinalityEstimator) -> Self:
|
|
@@ -564,8 +591,8 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
564
591
|
def build(self) -> Self:
|
|
565
592
|
"""Constructs the optimization pipeline.
|
|
566
593
|
|
|
567
|
-
This includes checking all strategies for compatibility with the `target_db`. Afterwards, the pipeline is ready
|
|
568
|
-
optimize queries.
|
|
594
|
+
This includes checking all strategies for compatibility with the `target_db`. Afterwards, the pipeline is ready
|
|
595
|
+
to optimize queries.
|
|
569
596
|
|
|
570
597
|
Returns
|
|
571
598
|
-------
|
|
@@ -577,13 +604,6 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
577
604
|
UnsupportedSystemError
|
|
578
605
|
If any of the selected optimization stages is not compatible with the `target_db`.
|
|
579
606
|
"""
|
|
580
|
-
if self._card_est is None:
|
|
581
|
-
raise StateError("Missing cardinality estimator")
|
|
582
|
-
if self._cost_model is None:
|
|
583
|
-
raise StateError("Missing cost model")
|
|
584
|
-
if self._plan_enumerator is None:
|
|
585
|
-
raise StateError("Missing plan enumerator")
|
|
586
|
-
|
|
587
607
|
self._support_check = merge_checks(
|
|
588
608
|
[
|
|
589
609
|
self._card_est.pre_check(),
|
|
@@ -596,15 +616,45 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
596
616
|
self._build = True
|
|
597
617
|
return self
|
|
598
618
|
|
|
619
|
+
@override
|
|
599
620
|
def query_execution_plan(self, query: SqlQuery) -> QueryPlan:
|
|
600
621
|
if not self._build:
|
|
601
622
|
raise StateError("Pipeline has not been build")
|
|
623
|
+
|
|
624
|
+
if self._default_card_est and self._default_cost_model and self._default_plan_enum:
|
|
625
|
+
return self._target_db.optimizer().query_plan(query)
|
|
626
|
+
|
|
602
627
|
self._support_check.check_supported_query(query).ensure_all_passed(query)
|
|
628
|
+
if not self._default_card_est and self._default_cost_model and self._default_plan_enum:
|
|
629
|
+
cardinalities = self._card_est.estimate_cardinalities(query)
|
|
630
|
+
hinted = self._target_db.hinting().generate_hints(query, plan_parameters=cardinalities)
|
|
631
|
+
return self._target_db.optimizer().query_plan(hinted)
|
|
603
632
|
|
|
604
633
|
return self._plan_enumerator.generate_execution_plan(
|
|
605
634
|
query, cardinality_estimator=self._card_est, cost_model=self._cost_model
|
|
606
635
|
)
|
|
607
636
|
|
|
637
|
+
@override
|
|
638
|
+
def optimize_query(self, query: SqlQuery) -> SqlQuery:
|
|
639
|
+
if not self._build:
|
|
640
|
+
raise StateError("Pipeline has not been build")
|
|
641
|
+
|
|
642
|
+
if self._default_card_est and self._default_cost_model and self._default_plan_enum:
|
|
643
|
+
return query
|
|
644
|
+
|
|
645
|
+
self._support_check.check_supported_query(query).ensure_all_passed(query)
|
|
646
|
+
if not self._default_card_est and self._default_cost_model and self._default_plan_enum:
|
|
647
|
+
cardinalities = self._card_est.estimate_cardinalities(query)
|
|
648
|
+
hinted = self._target_db.hinting().generate_hints(query, plan_parameters=cardinalities)
|
|
649
|
+
return hinted
|
|
650
|
+
|
|
651
|
+
plan = self._plan_enumerator.generate_execution_plan(
|
|
652
|
+
query, cardinality_estimator=self._card_est, cost_model=self._cost_model
|
|
653
|
+
)
|
|
654
|
+
hinted = self._target_db.hinting().generate_hints(query, plan)
|
|
655
|
+
return hinted
|
|
656
|
+
|
|
657
|
+
@override
|
|
608
658
|
def stages(self) -> list[OptimizationStage]:
|
|
609
659
|
s: list[OptimizationStage] = []
|
|
610
660
|
if self._plan_enumerator is not None:
|
|
@@ -615,6 +665,7 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
615
665
|
s.append(self._card_est)
|
|
616
666
|
return s
|
|
617
667
|
|
|
668
|
+
@override
|
|
618
669
|
def describe(self) -> jsondict:
|
|
619
670
|
enumerator = self._plan_enumerator.describe() if self._plan_enumerator is not None else None
|
|
620
671
|
cost_model = self._cost_model.describe() if self._cost_model is not None else None
|
|
@@ -628,9 +679,11 @@ class TextBookOptimizationPipeline(OptimizationPipeline):
|
|
|
628
679
|
"cardinality_estimator": cardinality_estimator,
|
|
629
680
|
}
|
|
630
681
|
|
|
682
|
+
@override
|
|
631
683
|
def __repr__(self) -> str:
|
|
632
684
|
return str(self)
|
|
633
685
|
|
|
686
|
+
@override
|
|
634
687
|
def __str__(self) -> str:
|
|
635
688
|
components = [self._plan_enumerator, self._cost_model, self._card_est]
|
|
636
689
|
opt_chain = " + ".join(str(comp) for comp in components)
|
|
@@ -935,13 +988,16 @@ class MultiStageOptimizationPipeline(OptimizationPipeline):
|
|
|
935
988
|
self._build = True
|
|
936
989
|
return self
|
|
937
990
|
|
|
991
|
+
@override
|
|
938
992
|
def target_database(self) -> Database:
|
|
939
993
|
return self.target_db
|
|
940
994
|
|
|
995
|
+
@override
|
|
941
996
|
def query_execution_plan(self, query: SqlQuery) -> QueryPlan:
|
|
942
997
|
optimized_query = self.optimize_query(query)
|
|
943
998
|
return self.target_db.optimizer().query_plan(optimized_query)
|
|
944
999
|
|
|
1000
|
+
@override
|
|
945
1001
|
def optimize_query(self, query: SqlQuery) -> SqlQuery:
|
|
946
1002
|
self._assert_is_build()
|
|
947
1003
|
assert self._pre_check is not None
|
|
@@ -979,6 +1035,7 @@ class MultiStageOptimizationPipeline(OptimizationPipeline):
|
|
|
979
1035
|
plan_parameters=plan_parameters,
|
|
980
1036
|
)
|
|
981
1037
|
|
|
1038
|
+
@override
|
|
982
1039
|
def stages(self) -> list[OptimizationStage]:
|
|
983
1040
|
s: list[OptimizationStage] = []
|
|
984
1041
|
if self._join_order_enumerator:
|
|
@@ -989,6 +1046,7 @@ class MultiStageOptimizationPipeline(OptimizationPipeline):
|
|
|
989
1046
|
s.append(self._plan_parameterization)
|
|
990
1047
|
return s
|
|
991
1048
|
|
|
1049
|
+
@override
|
|
992
1050
|
def describe(self) -> jsondict:
|
|
993
1051
|
return {
|
|
994
1052
|
"name": "multi_stage_pipeline",
|
|
@@ -1006,9 +1064,11 @@ class MultiStageOptimizationPipeline(OptimizationPipeline):
|
|
|
1006
1064
|
if not self._build:
|
|
1007
1065
|
raise StateError("Pipeline has not been build")
|
|
1008
1066
|
|
|
1067
|
+
@override
|
|
1009
1068
|
def __repr__(self) -> str:
|
|
1010
1069
|
return str(self)
|
|
1011
1070
|
|
|
1071
|
+
@override
|
|
1012
1072
|
def __str__(self) -> str:
|
|
1013
1073
|
components = [
|
|
1014
1074
|
self._join_order_enumerator,
|
|
@@ -1117,9 +1177,11 @@ class IncrementalOptimizationPipeline(OptimizationPipeline):
|
|
|
1117
1177
|
case _:
|
|
1118
1178
|
raise TypeError(f"Unsupported component type: {type(step)}")
|
|
1119
1179
|
|
|
1180
|
+
@override
|
|
1120
1181
|
def target_database(self) -> Database:
|
|
1121
1182
|
return self.target_db
|
|
1122
1183
|
|
|
1184
|
+
@override
|
|
1123
1185
|
def query_execution_plan(self, query: SqlQuery) -> QueryPlan:
|
|
1124
1186
|
self._ensure_supported_query(query)
|
|
1125
1187
|
current_plan = (
|
|
@@ -1131,6 +1193,7 @@ class IncrementalOptimizationPipeline(OptimizationPipeline):
|
|
|
1131
1193
|
current_plan = optimization_step.optimize_query(query, current_plan)
|
|
1132
1194
|
return current_plan
|
|
1133
1195
|
|
|
1196
|
+
@override
|
|
1134
1197
|
def stages(self) -> list[OptimizationStage]:
|
|
1135
1198
|
s: list[OptimizationStage] = []
|
|
1136
1199
|
if self._initial_plan_generator:
|
|
@@ -1138,6 +1201,7 @@ class IncrementalOptimizationPipeline(OptimizationPipeline):
|
|
|
1138
1201
|
s.extend(self._optimization_steps)
|
|
1139
1202
|
return s
|
|
1140
1203
|
|
|
1204
|
+
@override
|
|
1141
1205
|
def describe(self) -> jsondict:
|
|
1142
1206
|
return {
|
|
1143
1207
|
"name": "incremental_pipeline",
|
|
@@ -1214,9 +1278,11 @@ class IncrementalOptimizationPipeline(OptimizationPipeline):
|
|
|
1214
1278
|
continue
|
|
1215
1279
|
incremental_step.pre_check().check_supported_query(query).ensure_all_passed(query)
|
|
1216
1280
|
|
|
1281
|
+
@override
|
|
1217
1282
|
def __repr__(self) -> str:
|
|
1218
1283
|
return str(self)
|
|
1219
1284
|
|
|
1285
|
+
@override
|
|
1220
1286
|
def __str__(self) -> str:
|
|
1221
1287
|
opt_chain = " -> ".join(str(comp) for comp in self._optimization_steps)
|
|
1222
1288
|
return f"MultiStageOptimization [{opt_chain}]"
|