PostBOUND 0.19.0__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.19.0/LICENSE.txt +202 -0
- postbound-0.19.0/PKG-INFO +355 -0
- postbound-0.19.0/PostBOUND.egg-info/PKG-INFO +355 -0
- postbound-0.19.0/PostBOUND.egg-info/SOURCES.txt +77 -0
- postbound-0.19.0/PostBOUND.egg-info/dependency_links.txt +1 -0
- postbound-0.19.0/PostBOUND.egg-info/requires.txt +17 -0
- postbound-0.19.0/PostBOUND.egg-info/top_level.txt +1 -0
- postbound-0.19.0/README.md +322 -0
- postbound-0.19.0/postbound/__init__.py +211 -0
- postbound-0.19.0/postbound/_base.py +6 -0
- postbound-0.19.0/postbound/_bench.py +1012 -0
- postbound-0.19.0/postbound/_core.py +1153 -0
- postbound-0.19.0/postbound/_hints.py +1373 -0
- postbound-0.19.0/postbound/_jointree.py +1079 -0
- postbound-0.19.0/postbound/_pipelines.py +1121 -0
- postbound-0.19.0/postbound/_qep.py +1986 -0
- postbound-0.19.0/postbound/_stages.py +876 -0
- postbound-0.19.0/postbound/_validation.py +734 -0
- postbound-0.19.0/postbound/db/__init__.py +72 -0
- postbound-0.19.0/postbound/db/_db.py +2348 -0
- postbound-0.19.0/postbound/db/_duckdb.py +785 -0
- postbound-0.19.0/postbound/db/mysql.py +1195 -0
- postbound-0.19.0/postbound/db/postgres.py +4216 -0
- postbound-0.19.0/postbound/experiments/__init__.py +12 -0
- postbound-0.19.0/postbound/experiments/analysis.py +674 -0
- postbound-0.19.0/postbound/experiments/benchmarking.py +54 -0
- postbound-0.19.0/postbound/experiments/ceb.py +877 -0
- postbound-0.19.0/postbound/experiments/interactive.py +105 -0
- postbound-0.19.0/postbound/experiments/querygen.py +334 -0
- postbound-0.19.0/postbound/experiments/workloads.py +980 -0
- postbound-0.19.0/postbound/optimizer/__init__.py +92 -0
- postbound-0.19.0/postbound/optimizer/__init__.pyi +73 -0
- postbound-0.19.0/postbound/optimizer/_cardinalities.py +369 -0
- postbound-0.19.0/postbound/optimizer/_joingraph.py +1150 -0
- postbound-0.19.0/postbound/optimizer/dynprog.py +1825 -0
- postbound-0.19.0/postbound/optimizer/enumeration.py +432 -0
- postbound-0.19.0/postbound/optimizer/native.py +539 -0
- postbound-0.19.0/postbound/optimizer/noopt.py +54 -0
- postbound-0.19.0/postbound/optimizer/presets.py +147 -0
- postbound-0.19.0/postbound/optimizer/randomized.py +650 -0
- postbound-0.19.0/postbound/optimizer/tonic.py +1479 -0
- postbound-0.19.0/postbound/optimizer/ues.py +1607 -0
- postbound-0.19.0/postbound/qal/__init__.py +343 -0
- postbound-0.19.0/postbound/qal/_qal.py +9678 -0
- postbound-0.19.0/postbound/qal/formatter.py +1089 -0
- postbound-0.19.0/postbound/qal/parser.py +2344 -0
- postbound-0.19.0/postbound/qal/relalg.py +4257 -0
- postbound-0.19.0/postbound/qal/transform.py +2184 -0
- postbound-0.19.0/postbound/shortcuts.py +70 -0
- postbound-0.19.0/postbound/util/__init__.py +46 -0
- postbound-0.19.0/postbound/util/_errors.py +33 -0
- postbound-0.19.0/postbound/util/collections.py +490 -0
- postbound-0.19.0/postbound/util/dataframe.py +71 -0
- postbound-0.19.0/postbound/util/dicts.py +330 -0
- postbound-0.19.0/postbound/util/jsonize.py +68 -0
- postbound-0.19.0/postbound/util/logging.py +106 -0
- postbound-0.19.0/postbound/util/misc.py +168 -0
- postbound-0.19.0/postbound/util/networkx.py +401 -0
- postbound-0.19.0/postbound/util/numbers.py +438 -0
- postbound-0.19.0/postbound/util/proc.py +107 -0
- postbound-0.19.0/postbound/util/stats.py +37 -0
- postbound-0.19.0/postbound/util/system.py +48 -0
- postbound-0.19.0/postbound/util/typing.py +35 -0
- postbound-0.19.0/postbound/vis/__init__.py +5 -0
- postbound-0.19.0/postbound/vis/fdl.py +69 -0
- postbound-0.19.0/postbound/vis/graphs.py +48 -0
- postbound-0.19.0/postbound/vis/optimizer.py +538 -0
- postbound-0.19.0/postbound/vis/plots.py +84 -0
- postbound-0.19.0/postbound/vis/tonic.py +70 -0
- postbound-0.19.0/postbound/vis/trees.py +105 -0
- postbound-0.19.0/pyproject.toml +49 -0
- postbound-0.19.0/setup.cfg +4 -0
- postbound-0.19.0/tests/test_postgres.py +96 -0
- postbound-0.19.0/tests/test_qal.py +649 -0
- postbound-0.19.0/tests/test_relalg.py +277 -0
- postbound-0.19.0/tests/test_samples.py +32 -0
- postbound-0.19.0/tests/test_tonic_optimization.py +42 -0
- postbound-0.19.0/tests/test_ues_optimization.py +215 -0
- postbound-0.19.0/tests/test_util.py +60 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PostBOUND
|
|
3
|
+
Version: 0.19.0
|
|
4
|
+
Summary: PostBOUND is a research framework to prototype and benchmark database query optimizers
|
|
5
|
+
Author-email: Rico Bergmann <rico.bergmann1@tu-dresden.de>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/rbergm/PostBOUND
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Topic :: Database :: Database Engines/Servers
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE.txt
|
|
17
|
+
Requires-Dist: lazy-loader~=0.4
|
|
18
|
+
Requires-Dist: levenshtein~=0.27
|
|
19
|
+
Requires-Dist: natsort~=8.4
|
|
20
|
+
Requires-Dist: networkx~=3.5
|
|
21
|
+
Requires-Dist: numpy~=2.3
|
|
22
|
+
Requires-Dist: pandas~=2.3
|
|
23
|
+
Requires-Dist: pglast~=7.10
|
|
24
|
+
Requires-Dist: psycopg[binary]~=3.2
|
|
25
|
+
Requires-Dist: tqdm~=4.67
|
|
26
|
+
Provides-Extra: vis
|
|
27
|
+
Requires-Dist: matplotlib~=3.10; extra == "vis"
|
|
28
|
+
Requires-Dist: seaborn~=0.13; extra == "vis"
|
|
29
|
+
Requires-Dist: graphviz~=0.21; extra == "vis"
|
|
30
|
+
Provides-Extra: mysql
|
|
31
|
+
Requires-Dist: mysql-connector-python~=9.5; extra == "mysql"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# PostBOUND
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
<p align="center">
|
|
40
|
+
<img src="docs/figures/postbound-logo.svg" style="width: 150px; margin: 15px;">
|
|
41
|
+
</p>
|
|
42
|
+
|
|
43
|
+
PostBOUND is a Python framework for studying query optimization in database systems.
|
|
44
|
+
At a high level, PostBOUND has the following goals and features:
|
|
45
|
+
|
|
46
|
+
- 🏃♀️ **Rapid prototyping:** PostBOUND allows researchers to implement specific phases of the optimization process, such
|
|
47
|
+
as the cardinality estimator or the join order optimization. Researchers can focus precisely on the parts that they are
|
|
48
|
+
studying and use _reasonable_ defaults for the rest. See [🧑🏫 Example](#-example) for how this looks in practice.
|
|
49
|
+
- 🧰 **No boilerplate:** to ease the implementation of the optimizers, PostBOUND provides a large toolbox of
|
|
50
|
+
support functionality, such as query parsing, join graph construction, relational algebra or database statistics.
|
|
51
|
+
- 📊 **Transparent benchmarks:** once a new optimizer prototype is completed, the benchmarking tools allow to compare this
|
|
52
|
+
prototype against other optimization strategies in a transparent and reproducible way. As a core design principle,
|
|
53
|
+
PostBOUND executes queries on an actual database system such as PostgreSQL, or DuckDB, rather than research systems or
|
|
54
|
+
artificial "lab" comparisons. See [💡 Essentials](#-essentials) for more information on this.
|
|
55
|
+
- 🔋 **Batteries included:** in addition to the Python package, PostBOUND provides a lot of utilities to setup databases
|
|
56
|
+
and load commonly used benchmarks (e.g., JOB, Stats and Stack).
|
|
57
|
+
|
|
58
|
+
| **[💻 Installation](https://postbound.readthedocs.io/en/latest/setup.html)**
|
|
59
|
+
| **[📖 Documentation](https://postbound.readthedocs.io/en/latest/)**
|
|
60
|
+
| **[🧑🏫 Examples](https://github.com/rbergm/PostBOUND/tree/main/examples)** |
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## ⚡️ Quick Start
|
|
64
|
+
|
|
65
|
+
An installation of PostBOUND consists of two parts: the PostBOUND framework itself, as well as a running database instance
|
|
66
|
+
(such as PostgreSQL or DuckDB) that is used to actually execute the optimized queries (see [💡 Essentials](#-essentials)
|
|
67
|
+
below).
|
|
68
|
+
|
|
69
|
+
The easiest way to install PostBOUND is via Pip:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
pip install postbound
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Afterwards, you can [connect](https://postbound.readthedocs.io/en/latest/10minutes.html#database-connection) it to a
|
|
76
|
+
Postgres server running [pg_hint_plan](https://github.com/ossc-db/pg_hint_plan).
|
|
77
|
+
|
|
78
|
+
If you prefer a more integrated setup, we provide a Docker image that contains PostBOUND as well as a readily-configured
|
|
79
|
+
Postgres server or DuckDB installation.
|
|
80
|
+
You can build your Docker image with the following command:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
docker build -t postbound --build-arg TIMEZONE=$(cat /etc/timezone) .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Once the image is built, you can create any number of containers with different setups.
|
|
87
|
+
For example, to create a container with a local Postgres instance (using [pg_lab](https://github.com/rbergm/pg_lab)) and
|
|
88
|
+
setup the Stats, JOB and Stack benchmarks, use the following command:
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
docker run -dt \
|
|
93
|
+
--shm-size 4G \
|
|
94
|
+
--name postbound \
|
|
95
|
+
--env USE_PGLAB=true \
|
|
96
|
+
--env OPTIMIZE_PG_CONFIG=true \
|
|
97
|
+
--env SETUP_DUCKDB=false \
|
|
98
|
+
--env SETUP_STATS=true \
|
|
99
|
+
--env SETUP_JOB=false \
|
|
100
|
+
--env SETUP_STACK=false \
|
|
101
|
+
--volume $PWD/vol-postbound:/postbound \
|
|
102
|
+
--volume $PWD/vol-pglab:/pg_lab \
|
|
103
|
+
--publish 5432:5432 \
|
|
104
|
+
--publish 8888:8888 \
|
|
105
|
+
postbound
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
All supported build arguments are listed under [Docker options](#-docker-options).
|
|
109
|
+
See [Essentials](#-essentials) for why a database instance is necessary.
|
|
110
|
+
For Postgres, adjust the amount of shared memory depending on your machine.
|
|
111
|
+
Note that the initial start of the container will take a substantial amount of time.
|
|
112
|
+
This is because the container needs to compile a fresh Postgres server from source, download and import workloads, etc.
|
|
113
|
+
Use `docker logs -f postbound` to monitor the startup process.
|
|
114
|
+
|
|
115
|
+
> [!TIP]
|
|
116
|
+
> Shared memory is used by Postgres for its internal caching and therefore paramount for good server performance.
|
|
117
|
+
> The general recommendation is to set it to at least 1/4 of the available RAM.
|
|
118
|
+
|
|
119
|
+
The Postgres server will be available at port 5432 from the host machine (using the user _postbound_ with the same
|
|
120
|
+
password).
|
|
121
|
+
You can also create a local DuckDB installation by setting `SETUP_DUCKDB` to _true_.
|
|
122
|
+
If you plan on using Jupyter for data analysis, also publish port 8888.
|
|
123
|
+
The volume mountpoints provide all internal files from PostBOUND and pg_lab (if used).
|
|
124
|
+
|
|
125
|
+
You can connect to the PostBOUND container using the usual
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
docker exec -it postbound /bin/bash
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The shell enviroment is setup to have PostBOUND available in a fresh Python virtual environment (which is activated by
|
|
132
|
+
default).
|
|
133
|
+
Furthermore, all Postgres and DuckDB utilities are available on the _PATH_ (if the respective systems have been build during
|
|
134
|
+
the setup).
|
|
135
|
+
|
|
136
|
+
> [!TIP]
|
|
137
|
+
> If you want to install PostBOUND directly on your machine, the
|
|
138
|
+
> [documentation](https://postbound.readthedocs.io/en/latest/setup.html) provides a detailed setup guide.
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
## 💡 Essentials
|
|
142
|
+
|
|
143
|
+
As a central design decision, PostBOUND is not integrated into a specific database system.
|
|
144
|
+
Instead, it is implemented as a Python framework operating on top of a running database instance.
|
|
145
|
+
In the end, all query plans generated by PostBOUND should be executed on a real-world database system.
|
|
146
|
+
This decision was made to ensure that the optimization strategies are actually useful in practice and we treat the execution
|
|
147
|
+
time as the ultimate measure of optimization quality.
|
|
148
|
+
|
|
149
|
+
However, this decision means that we need a way to ensure that the optimization decisions made within the framework are
|
|
150
|
+
actually used when executing the query in the context of the target database.
|
|
151
|
+
This is achieved by using query hints which typically encode the optimization decisions in comment blocks within the query.
|
|
152
|
+
|
|
153
|
+
In the case of Postgres, this interaction roughly looks like this:
|
|
154
|
+
|
|
155
|
+
<p align="center">
|
|
156
|
+
<img src="docs/figures/postbound-pg-interaction.svg" style="width: 600px; margin: 15px;">
|
|
157
|
+
</p>
|
|
158
|
+
|
|
159
|
+
Users implement their optimization strategies in terms of
|
|
160
|
+
[optimization pipelines](https://postbound.readthedocs.io/en/latest/core/optimization.html).
|
|
161
|
+
For an incoming SQL query, the pipeline computes an abstract representation of the resulting query plan without user
|
|
162
|
+
intervention.
|
|
163
|
+
This plan is automatically converted into equivalent hints for the target database system such as Postgres or DuckDB.
|
|
164
|
+
Afterwards, the hints ensure that the database system executes the query plan that was originally computed in the optimization
|
|
165
|
+
pipeline.
|
|
166
|
+
|
|
167
|
+
Depending on the actual database system, the hints might differ in syntax as well as semantics.
|
|
168
|
+
Generally speaking, PostBOUND figures out which hints to use on its own, without user intervention.
|
|
169
|
+
In the case of PostgreSQL, PostBOUND relies on either [pg_hint_plan](https://github.com/ossc-db/pg_hint_plan) or
|
|
170
|
+
[pg_lab](https://github.com/rbergm/pg_lab) to provide the necessary hinting functionality when targeting Postgres.
|
|
171
|
+
For DuckDB, PostBOUND uses [quacklab](https://github.com/rbergm/quacklab) hints to guide the optimizer.
|
|
172
|
+
|
|
173
|
+
> [!NOTE]
|
|
174
|
+
> PostBOUND's database interaction is designed to be independent of a specific system (such as PostgreSQL, Oracle, ...).
|
|
175
|
+
> However, the current implementation is most complete for PostgreSQL and DuckDB with limited support for MySQL.
|
|
176
|
+
> This is due to practical reasons, mostly our own time budget and the popularity of the two systems in the optimizer research
|
|
177
|
+
> community.
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## 🧑🏫 Example
|
|
181
|
+
|
|
182
|
+
The typical end-to-end workflow using PostBOUND looks like this:
|
|
183
|
+
|
|
184
|
+
1. **Implement your new optimization strategy**. To do so, you need to figure out which parts of the optimization process you
|
|
185
|
+
want to customize and what the most appropriate optimization pipeline is. In a nutshell, the optimization pipeline is
|
|
186
|
+
a mental model of how the optimizer works. Commonly used pipelines are the textbook-style pipeline (i.e. using plan
|
|
187
|
+
enumerator, cost model and cardinality estimator), or the multi-stage pipeline which first computes a join order and
|
|
188
|
+
afterwards selects the best physical operators. The pipeline determines which interfaces can be implemented.
|
|
189
|
+
2. Select your **target database system** and **benchmark** that should be used for the evaluation.
|
|
190
|
+
3. Optionally, select different optimization strategies that you want to compare against.
|
|
191
|
+
4. Use the **benchmarking tools** to execute the workload against the target database system.
|
|
192
|
+
|
|
193
|
+
For example, a random join order optimizer could be implemented like this:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
import random
|
|
197
|
+
|
|
198
|
+
import postbound as pb
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
# Step 1: define our optimization strategy.
|
|
202
|
+
# In this example we develop a simple join order optimizer that
|
|
203
|
+
# selects a linear join order at random.
|
|
204
|
+
# We delegate most of the actual work to the pre-defined join grap
|
|
205
|
+
# that keeps track of free tables.
|
|
206
|
+
class RandomJoinOrderOptimizer(pb.JoinOrderOptimization):
|
|
207
|
+
def optimize_join_order(self, query: pb.SqlQuery) -> pb.LogicalJoinTree:
|
|
208
|
+
join_tree = pb.LogicalJoinTree()
|
|
209
|
+
join_graph = pb.opt.JoinGraph(query)
|
|
210
|
+
|
|
211
|
+
while join_graph.contains_free_tables():
|
|
212
|
+
candidate_tables = [
|
|
213
|
+
path.target_table for path in join_graph.available_join_paths()
|
|
214
|
+
]
|
|
215
|
+
next_table = random.choice(candidate_tables)
|
|
216
|
+
|
|
217
|
+
join_tree = join_tree.join_with(next_table)
|
|
218
|
+
join_graph.mark_joined(next_table)
|
|
219
|
+
|
|
220
|
+
return join_tree
|
|
221
|
+
|
|
222
|
+
def describe(self) -> pb.util.jsondict:
|
|
223
|
+
return {"name": "random-join-order"}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
# Step 2: connect to the target database, load the workload and
|
|
227
|
+
# setup the optimization pipeline.
|
|
228
|
+
# In our case, we evaluate on the Join Order Benchmark on Postgres
|
|
229
|
+
pg_imdb = pb.postgres.connect(config_file=".psycopg_connection_job")
|
|
230
|
+
job = pb.workloads.job()
|
|
231
|
+
|
|
232
|
+
optimization_pipeline = (
|
|
233
|
+
pb.MultiStageOptimizationPipeline(pg_imdb)
|
|
234
|
+
.use(RandomJoinOrderOptimizer())
|
|
235
|
+
.build()
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
# (Step 3): in this example we just compare against the native Postgres optimizer
|
|
239
|
+
# Therefore, we do not need to setup any additional optimizers.
|
|
240
|
+
|
|
241
|
+
# Step 4: execute the workload.
|
|
242
|
+
# We use the QueryPreparationService to prewarm the database buffer and run all
|
|
243
|
+
# queries as EXPLAIN ANALYZE.
|
|
244
|
+
query_prep = pb.bench.QueryPreparation(
|
|
245
|
+
prewarm=True, analyze=True, preparatory_statements=["SET geqo TO off;"]
|
|
246
|
+
)
|
|
247
|
+
native_results = pb.bench.execute_workload(
|
|
248
|
+
job,
|
|
249
|
+
on=pg_imdb,
|
|
250
|
+
query_preparation=query_prep,
|
|
251
|
+
workload_repetitions=3,
|
|
252
|
+
progressive_output="job-results-native.csv",
|
|
253
|
+
logger="tqdm",
|
|
254
|
+
)
|
|
255
|
+
optimized_results = pb.bench.execute_workload(
|
|
256
|
+
job,
|
|
257
|
+
on=optimization_pipeline,
|
|
258
|
+
query_preparation=query_prep,
|
|
259
|
+
workload_repetitions=3,
|
|
260
|
+
progressive_output="job-results-optimized.csv",
|
|
261
|
+
logger="tqdm",
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
## 🤬 Issues
|
|
268
|
+
|
|
269
|
+
Something feels wrong or broken, or a part of PostBOUND is poorly documented or otherwise unclear?
|
|
270
|
+
Please don't hestitate to file an issue or open a pull request!
|
|
271
|
+
PostBOUND is not one-off software, but an ongoing research project.
|
|
272
|
+
We are always happy to improve both PostBOUND and its documentation and we feel that the user experience (specifically,
|
|
273
|
+
_your_ user experience) is a very important part of this.
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
## 🫶 Reference
|
|
277
|
+
|
|
278
|
+
If you find our work useful, please cite the following paper:
|
|
279
|
+
|
|
280
|
+
```bibtex
|
|
281
|
+
@inproceedings{bergmann2025elephant,
|
|
282
|
+
author = {Rico Bergmann and
|
|
283
|
+
Claudio Hartmann and
|
|
284
|
+
Dirk Habich and
|
|
285
|
+
Wolfgang Lehner},
|
|
286
|
+
title = {An Elephant Under the Microscope: Analyzing the Interaction of Optimizer
|
|
287
|
+
Components in PostgreSQL},
|
|
288
|
+
journal = {Proc. {ACM} Manag. Data},
|
|
289
|
+
volume = {3},
|
|
290
|
+
number = {1},
|
|
291
|
+
pages = {9:1--9:28},
|
|
292
|
+
year = {2025},
|
|
293
|
+
url = {https://doi.org/10.1145/3709659},
|
|
294
|
+
doi = {10.1145/3709659},
|
|
295
|
+
timestamp = {Tue, 01 Apr 2025 19:03:19 +0200},
|
|
296
|
+
biburl = {https://dblp.org/rec/journals/pacmmod/BergmannHHL25.bib},
|
|
297
|
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
## 📖 Documentation
|
|
305
|
+
|
|
306
|
+
A detailed documentation of PostBOUND is available [here](https://postbound.readthedocs.io/en/latest/).
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
## 🐳 Docker options
|
|
310
|
+
|
|
311
|
+
The following options can be used when starting the Docker container as `--env` parameters (with the exception of _TIMEZONE_,
|
|
312
|
+
which must be specified as a `--build-arg` when creating the image).
|
|
313
|
+
|
|
314
|
+
| Argument | Allowed values | Description | Default |
|
|
315
|
+
|----------|----------------|-------------|---------|
|
|
316
|
+
| `TIMEZONE` | Any valid timezone identifier | Timezone of the Docker container (and hence the Postgres server). It is probably best to just use the value of `cat /etc/timezone` | `UTC` |
|
|
317
|
+
| `USERNAME` | Any valid UNIX username. | The username within the Docker container. This will also be the Postgres user and password. | `postbound` |
|
|
318
|
+
| `SETUP_POSTGRES` | `true` or `false` | Whether to include a Postgres server in the setup. By default, this is a vanilla Postgres server with the latest minor release. However, this can be customized with `USE_PGLAB` and `PGVER`. | `true` |
|
|
319
|
+
| `USE_PGLAB` | `true` or `false` | Whether to initialize a [pg_lab](https://github.com/rbergm/pg_lab) server instead of a normal Postgres server. pg_lab provides advanced hinting capabilities and offers additional extension points for the query optimizer. | `false` |
|
|
320
|
+
| `OPTIMIZE_PG_CONFIG` | `true` or `false` | Whether the Postgres configuration parameters should be automatically set based on your hardware platform. Rules are based on [PGTune](https://pgtune.leopard.in.ua/) by [le0pard](https://github.com/le0pard). | `false` |
|
|
321
|
+
| `PG_DISK_TYPE` | `SSD` or `HDD` | In case the Postgres server is automatically configured (see `OPTIMIZE_PG_CONFIG`) this indicates the kind of storage for the actual database. In turn, this influences the relative cost of sequential access and index-based access for the query optimizer. | `SSD` |
|
|
322
|
+
| `PGVER` | 16, 17, ... | The Postgres version to use. Notice that pg_lab supports fewer versions. This value is passed to the `postgres-setup.sh` script of the Postgres tooling (either under `db-support` or from pg_lab), which provides the most up to date list of supported versions. | 17 |
|
|
323
|
+
| `SETUP_DUCKDB` | `true` or `false` | Whether DuckDB-support should be added to PostBOUND. If enabled, a [DuckDB version with hinting support](https://github.com/rbergm/quacklab) will be compiled and images for all selected benchmarks will be created. Please be aware that during testing we noticed that creating an optimized build of DuckDB takes a lot of time on some platforms (think a couple of hours). | `false` |
|
|
324
|
+
| `SETUP_IMDB` | `true` or `false` | Whether an [IMDB](https://doi.org/10.14778/2850583.2850594) instance should be created as part of the setup. If a Postgres server is included in the setup, PostBOUND can connect to the database using the `.psycopg_connection_job` config file. For DuckDB, the database will be located at `/postbound/imdb.duckdb`. | `false` |
|
|
325
|
+
| `SETUP_STATS` | `true` or `false` | Whether a [Stats](https://doi.org/10.14778/3503585.3503586) instance should be created as part of the setup. If a Postgres server is included in the setup, PostBOUND can connect to the database using the `.psycopg_connection_stats` config file. For DuckDB, the database will be located at `/postbound/stats.duckdb` | `false` |
|
|
326
|
+
| `SETUP_STACK` | `true` or `false`| Whether a [Stack](https://doi.org/10.1145/3448016.3452838) instance should be created as part of the Postgres setup. If a Postgres server is included in the setup, PostBOUND can connect to the database using the `.psycopg_connection_stack` config file. DuckDB is currently not supported. | `false` |
|
|
327
|
+
|
|
328
|
+
The PostBOUND source code is located at `/postbound`. If pg_lab is being used, the corresponding files are located at `/pg_lab`.
|
|
329
|
+
The container automatically exposes the Postgres port 5432 and provides volume mountpoints at `/postbound` and `/pg_lab`.
|
|
330
|
+
These mountpoints can be used as backups or to easily ingest data into the container.
|
|
331
|
+
If the pg_lab mountpoint points to an existing (i.e. non-empty) directory, the setup assumes that this is already a valid
|
|
332
|
+
pg_lab installation and skips the corresponding setup.
|
|
333
|
+
|
|
334
|
+
> [!TIP]
|
|
335
|
+
> pg_lab provides advanced hinting support (e.g. for materialization or cardinality hints for base tables) and offers
|
|
336
|
+
> additional extension points for the query optimizer (e.g. hooks for the different cost functions).
|
|
337
|
+
> If pg_lab is not used, the Postgres server will setup pg_hint_plan instead.
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
## 📑 Repo Structure
|
|
341
|
+
|
|
342
|
+
The repository is structured as follows.
|
|
343
|
+
The `postbound` directory contains the actual source code, all other folders are concerned with "supporting" aspects
|
|
344
|
+
(which are nevertheless important..).
|
|
345
|
+
Almost all of the subdirectories contain further READMEs that explain their purpose and structure in more detail.
|
|
346
|
+
|
|
347
|
+
| Folder | Description |
|
|
348
|
+
| ------------- | ----------- |
|
|
349
|
+
| `postbound` | Contains the source code of the PostBOUND framework |
|
|
350
|
+
| `docs` | contains the high-level documentation as well as infrastructure to export the source code documentation |
|
|
351
|
+
| `examples` | contains general examples for typical usage scenarios. These should be run from the root directory, e.g. as `python3 -m examples.example-01-basic-workflow` |
|
|
352
|
+
| `tests` | contains the unit tests and integration tests for the framework implementatino. These should also be run from the root directory, e.g. as `python3 -m unittest tests` |
|
|
353
|
+
| `db-support` | Contains utilities to setup instances of the respective database systems and contain system-specific scripts to import popular benchmarks for them |
|
|
354
|
+
| `workloads` | Contains the raw SQL queries of some popular benchmarks |
|
|
355
|
+
| `tools` | Provides different other utilities that are not directly concerned with specific database systems, but rather with common problems encoutered when benchmarking query optimizers |
|