PostBOUND 0.23.2__tar.gz → 0.23.4__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.
Files changed (79) hide show
  1. {postbound-0.23.2 → postbound-0.23.4}/PKG-INFO +1 -1
  2. {postbound-0.23.2 → postbound-0.23.4}/PostBOUND.egg-info/PKG-INFO +1 -1
  3. {postbound-0.23.2 → postbound-0.23.4}/postbound/_hints.py +14 -3
  4. {postbound-0.23.2 → postbound-0.23.4}/postbound/postgres/_explain.py +22 -12
  5. {postbound-0.23.2 → postbound-0.23.4}/postbound/postgres/_pg.py +3 -0
  6. {postbound-0.23.2 → postbound-0.23.4}/postbound/qal/_qal.py +5 -8
  7. {postbound-0.23.2 → postbound-0.23.4}/pyproject.toml +1 -1
  8. {postbound-0.23.2 → postbound-0.23.4}/LICENSE.txt +0 -0
  9. {postbound-0.23.2 → postbound-0.23.4}/PostBOUND.egg-info/SOURCES.txt +0 -0
  10. {postbound-0.23.2 → postbound-0.23.4}/PostBOUND.egg-info/dependency_links.txt +0 -0
  11. {postbound-0.23.2 → postbound-0.23.4}/PostBOUND.egg-info/requires.txt +0 -0
  12. {postbound-0.23.2 → postbound-0.23.4}/PostBOUND.egg-info/top_level.txt +0 -0
  13. {postbound-0.23.2 → postbound-0.23.4}/README.md +0 -0
  14. {postbound-0.23.2 → postbound-0.23.4}/postbound/__init__.py +0 -0
  15. {postbound-0.23.2 → postbound-0.23.4}/postbound/__init__.pyi +0 -0
  16. {postbound-0.23.2 → postbound-0.23.4}/postbound/_base.py +0 -0
  17. {postbound-0.23.2 → postbound-0.23.4}/postbound/_core.py +0 -0
  18. {postbound-0.23.2 → postbound-0.23.4}/postbound/_ipython.py +0 -0
  19. {postbound-0.23.2 → postbound-0.23.4}/postbound/_pipelines.py +0 -0
  20. {postbound-0.23.2 → postbound-0.23.4}/postbound/_qep.py +0 -0
  21. {postbound-0.23.2 → postbound-0.23.4}/postbound/_stages.py +0 -0
  22. {postbound-0.23.2 → postbound-0.23.4}/postbound/bench.py +0 -0
  23. {postbound-0.23.2 → postbound-0.23.4}/postbound/db/__init__.py +0 -0
  24. {postbound-0.23.2 → postbound-0.23.4}/postbound/db/_cache.py +0 -0
  25. {postbound-0.23.2 → postbound-0.23.4}/postbound/db/_db.py +0 -0
  26. {postbound-0.23.2 → postbound-0.23.4}/postbound/db/_stats.py +0 -0
  27. {postbound-0.23.2 → postbound-0.23.4}/postbound/duckdb/__init__.py +0 -0
  28. {postbound-0.23.2 → postbound-0.23.4}/postbound/duckdb/_duckdb.py +0 -0
  29. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/__init__.py +0 -0
  30. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/__init__.pyi +0 -0
  31. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/_cardinalities.py +0 -0
  32. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/_dynprog.py +0 -0
  33. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/_enumeration.py +0 -0
  34. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/_helpers.py +0 -0
  35. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/_native.py +0 -0
  36. {postbound-0.23.2 → postbound-0.23.4}/postbound/opt/_randomized.py +0 -0
  37. {postbound-0.23.2 → postbound-0.23.4}/postbound/parser.py +0 -0
  38. {postbound-0.23.2 → postbound-0.23.4}/postbound/postgres/__init__.py +0 -0
  39. {postbound-0.23.2 → postbound-0.23.4}/postbound/postgres/_config.py +0 -0
  40. {postbound-0.23.2 → postbound-0.23.4}/postbound/postgres/_ctl.py +0 -0
  41. {postbound-0.23.2 → postbound-0.23.4}/postbound/qal/__init__.py +0 -0
  42. {postbound-0.23.2 → postbound-0.23.4}/postbound/qal/_formatter.py +0 -0
  43. {postbound-0.23.2 → postbound-0.23.4}/postbound/relalg.py +0 -0
  44. {postbound-0.23.2 → postbound-0.23.4}/postbound/train/__init__.py +0 -0
  45. {postbound-0.23.2 → postbound-0.23.4}/postbound/train/_train.py +0 -0
  46. {postbound-0.23.2 → postbound-0.23.4}/postbound/transform.py +0 -0
  47. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/__init__.py +0 -0
  48. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/__init__.pyi +0 -0
  49. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/_df.py +0 -0
  50. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/_errors.py +0 -0
  51. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/collections.py +0 -0
  52. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/dicts.py +0 -0
  53. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/jsonize.py +0 -0
  54. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/logging.py +0 -0
  55. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/misc.py +0 -0
  56. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/num.py +0 -0
  57. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/nx.py +0 -0
  58. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/proc.py +0 -0
  59. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/stats.py +0 -0
  60. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/system.py +0 -0
  61. {postbound-0.23.2 → postbound-0.23.4}/postbound/util/typing.py +0 -0
  62. {postbound-0.23.2 → postbound-0.23.4}/postbound/validation.py +0 -0
  63. {postbound-0.23.2 → postbound-0.23.4}/postbound/vis/__init__.py +0 -0
  64. {postbound-0.23.2 → postbound-0.23.4}/postbound/vis/__init__.pyi +0 -0
  65. {postbound-0.23.2 → postbound-0.23.4}/postbound/vis/fdl.py +0 -0
  66. {postbound-0.23.2 → postbound-0.23.4}/postbound/vis/graphs.py +0 -0
  67. {postbound-0.23.2 → postbound-0.23.4}/postbound/vis/optimizer.py +0 -0
  68. {postbound-0.23.2 → postbound-0.23.4}/postbound/vis/plots.py +0 -0
  69. {postbound-0.23.2 → postbound-0.23.4}/postbound/vis/trees.py +0 -0
  70. {postbound-0.23.2 → postbound-0.23.4}/postbound/workloads.py +0 -0
  71. {postbound-0.23.2 → postbound-0.23.4}/setup.cfg +0 -0
  72. {postbound-0.23.2 → postbound-0.23.4}/tests/test_benchmarking.py +0 -0
  73. {postbound-0.23.2 → postbound-0.23.4}/tests/test_core.py +0 -0
  74. {postbound-0.23.2 → postbound-0.23.4}/tests/test_docs.py +0 -0
  75. {postbound-0.23.2 → postbound-0.23.4}/tests/test_duckdb.py +0 -0
  76. {postbound-0.23.2 → postbound-0.23.4}/tests/test_postgres.py +0 -0
  77. {postbound-0.23.2 → postbound-0.23.4}/tests/test_qal.py +0 -0
  78. {postbound-0.23.2 → postbound-0.23.4}/tests/test_relalg.py +0 -0
  79. {postbound-0.23.2 → postbound-0.23.4}/tests/test_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PostBOUND
3
- Version: 0.23.2
3
+ Version: 0.23.4
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PostBOUND
3
- Version: 0.23.2
3
+ Version: 0.23.4
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
@@ -684,8 +684,12 @@ class PlanParameterization:
684
684
  PlanParameterization
685
685
  The parameters are updated in place and returned for chaining.
686
686
  """
687
+ tables = frozenset(tables)
688
+ if not tables:
689
+ raise ValueError("Cannot assign cardinality to an empty set of tables")
690
+
687
691
  cardinality = Cardinality.of(cardinality)
688
- self.cardinalities[frozenset(tables)] = cardinality
692
+ self.cardinalities[tables] = cardinality
689
693
  return self
690
694
 
691
695
  def set_workers(self, tables: Iterable[TableReference], num_workers: int) -> Self:
@@ -1694,6 +1698,13 @@ def parameters_from_plan(
1694
1698
  `fallback_estimated` is set.
1695
1699
  """
1696
1700
  params = PlanParameterization()
1701
+ tables = query_plan.tables()
1702
+ if not tables:
1703
+ # There are no more base tables left in the plan. No point to traverse further.
1704
+ # Note that this situation is completely legit: For example, consider Postgres Bitmap Scans:
1705
+ # The heap scan contains the actual table while its children (the index lookups) only reference
1706
+ # the indexes. Once we recurse from the heap scan into the index lookups, no base tables are left.
1707
+ return params
1697
1708
 
1698
1709
  if isinstance(query_plan, JoinTree):
1699
1710
  card = query_plan.annotation
@@ -1712,9 +1723,9 @@ def parameters_from_plan(
1712
1723
  parallel_workers = query_plan.params.parallel_workers
1713
1724
 
1714
1725
  if card is not None and not math.isnan(card):
1715
- params.add_cardinality(query_plan.tables(), card)
1726
+ params.add_cardinality(tables, card)
1716
1727
  if parallel_workers:
1717
- params.set_workers(query_plan.tables(), parallel_workers)
1728
+ params.set_workers(tables, parallel_workers)
1718
1729
 
1719
1730
  for child in query_plan.children:
1720
1731
  child_params = parameters_from_plan(
@@ -5,7 +5,7 @@ import warnings
5
5
  from collections.abc import Sequence
6
6
  from typing import Any, Literal, get_args, override
7
7
 
8
- from .._core import Cardinality, IntermediateOperator, JoinOperator, ScanOperator, TableReference
8
+ from .._core import Cardinality, IntermediateOperator, JoinOperator, ScanOperator, TableReference, TimeS
9
9
  from .._qep import QueryPlan, SortKey
10
10
 
11
11
  PostgresExplainJoinNodes = {
@@ -344,15 +344,15 @@ class PostgresExplain:
344
344
  )
345
345
  return TableReference(self.relation_name, alias)
346
346
 
347
- def as_qep(self) -> QueryPlan:
347
+ def as_qep(self, *, planning_time: TimeS = float("nan")) -> QueryPlan:
348
348
  """Transforms the postgres-specific plan to a standardized `QueryPlan` instance.
349
349
 
350
- Notice that this transformation is lossy since not all information from the Postgres plan can be represented in query
351
- execution plan instances. Furthermore, this transformation can be problematic for complicated queries that use
352
- special Postgres features. Most importantly, for queries involving subqueries, special node types and parent
353
- relationships can be contained in the plan, that cannot be represented by other parts of PostBOUND. If this method
354
- and the resulting query execution plans should be used on complex workloads, it is advisable to check the plans twice
355
- before continuing.
350
+ Notice that this transformation is lossy since not all information from the Postgres plan can be represented in
351
+ query execution plan instances. Furthermore, this transformation can be problematic for complicated queries that
352
+ use special Postgres features. Most importantly, for queries involving subqueries, special node types and parent
353
+ relationships can be contained in the plan, that cannot be represented by other parts of PostBOUND. If this
354
+ method and the resulting query execution plans should be used on complex workloads, it is advisable to check the
355
+ plans twice before continuing.
356
356
 
357
357
  Returns
358
358
  -------
@@ -364,7 +364,12 @@ class PostgresExplain:
364
364
  ValueError
365
365
  If the node contains more than two children.
366
366
  """
367
- return self._generate_qep()
367
+ qep = self._generate_qep()
368
+
369
+ if planning_time > 0:
370
+ qep.measures["planning_time"] = planning_time
371
+
372
+ return qep
368
373
 
369
374
  def _generate_qep(self, *, card_adjustment: float = 1.0) -> QueryPlan:
370
375
  child_nodes = []
@@ -442,6 +447,11 @@ class PostgresExplain:
442
447
  subplan_target_name=subplan_name,
443
448
  )
444
449
 
450
+ if not math.isnan(self.planned_workers):
451
+ plan.estimates["planned_workers"] = self.planned_workers
452
+ if not math.isnan(self.launched_workers):
453
+ plan.measures["launched_workers"] = self.launched_workers
454
+
445
455
  return plan
446
456
 
447
457
  def inspect(self, *, _indentation: int = 0) -> str:
@@ -551,10 +561,10 @@ class PostgresPlan:
551
561
  if not (isinstance(self.explain_data, dict) and "Plan" in self.explain_data):
552
562
  raise ValueError(f"Invalid explain data: missing 'Plan' key: {explain_data}")
553
563
 
554
- self.planning_time: float = self.explain_data.get("Planning Time", math.nan) / 1000
555
- self.execution_time: float = self.explain_data.get("Execution Time", math.nan) / 1000
564
+ self.planning_time: TimeS = self.explain_data.get("Planning Time", math.nan) / 1000
565
+ self.execution_time: TimeS = self.explain_data.get("Execution Time", math.nan) / 1000
556
566
  self.query_plan = PostgresExplain(self.explain_data["Plan"])
557
- self._normalized_plan = self.query_plan.as_qep()
567
+ self._normalized_plan = self.query_plan.as_qep(planning_time=self.planning_time)
558
568
 
559
569
  @property
560
570
  def root(self) -> PostgresExplain:
@@ -2361,6 +2361,9 @@ class PostgresOptimizer(OptimizerInterface):
2361
2361
  plan = plan[0]
2362
2362
  if isinstance(plan, tuple):
2363
2363
  plan = plan[0]
2364
+ if isinstance(plan, list):
2365
+ # the actual EXPLAIN output is wrapped in another list
2366
+ plan = plan[0]
2364
2367
 
2365
2368
  if not isinstance(plan, dict):
2366
2369
  warnings.warn(f"Could not parse plan: {plan}. Expected a dictionary, but got {type(plan)}.", stacklevel=2)
@@ -3727,7 +3727,7 @@ class PredicateVisitor(ABC, Generic[VisitorResult]):
3727
3727
  @overload
3728
3728
  def as_predicate(
3729
3729
  column: ColumnReference,
3730
- operation: Literal[BinaryOperator.In, "in", "IN"],
3730
+ operation: Literal[BinaryOperator.In, "in", "IN", BinaryOperator.NotIn, "not in", "NOT IN"],
3731
3731
  *arguments,
3732
3732
  ) -> InPredicate: ...
3733
3733
 
@@ -3843,12 +3843,9 @@ def as_predicate(column: ColumnReference, operation: BinaryOperator | UnaryOpera
3843
3843
  as_expression(upper, allow_star=False),
3844
3844
  ),
3845
3845
  )
3846
- elif operation == BinaryOperator.In:
3846
+ elif operation in (BinaryOperator.In, BinaryOperator.NotIn):
3847
3847
  arguments = util.flatten(arguments)
3848
- return InPredicate(
3849
- column,
3850
- [as_expression(value, allow_star=False) for value in arguments],
3851
- )
3848
+ return InPredicate(column, [as_expression(value, allow_star=False) for value in arguments], operator=operation)
3852
3849
  elif len(arguments) != 1:
3853
3850
  raise ValueError("Too many arguments for binary predicate: " + str(arguments))
3854
3851
 
@@ -4024,7 +4021,7 @@ def _attempt_filter_unwrap(
4024
4021
  assert isinstance(lhs, ColumnReference)
4025
4022
  return lhs, BinaryOperator.Between, (lower, upper)
4026
4023
 
4027
- case InPredicate(lhs, values):
4024
+ case InPredicate(lhs, values, op):
4028
4025
  status, lhs = _unwrap_expression(lhs)
4029
4026
  if not status:
4030
4027
  return None
@@ -4037,7 +4034,7 @@ def _attempt_filter_unwrap(
4037
4034
  unwrapped_vals.append(unwrapped)
4038
4035
 
4039
4036
  assert isinstance(lhs, ColumnReference)
4040
- return lhs, BinaryOperator.In, tuple(unwrapped_vals)
4037
+ return lhs, op, tuple(unwrapped_vals)
4041
4038
 
4042
4039
  case UnaryPredicate(col, op) if predicate.is_null_test() or predicate.is_bool_test():
4043
4040
  status, col = _unwrap_expression(col)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PostBOUND"
7
- version = "0.23.2"
7
+ version = "0.23.4"
8
8
  authors = [{ name = "Rico Bergmann", email = "rico.bergmann1@tu-dresden.de" }]
9
9
  description = "PostBOUND is a research framework to prototype and benchmark database query optimizers"
10
10
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes