README.md 8.9 KB
Newer Older
E
Entong Shen 已提交
1 2
<pre>
======================================================================
3
               __________  ____  ____  _________
4 5 6 7
              / ____/ __ \/ __ \/ __ \/ ____/   |
             / / __/ /_/ / / / / / /_/ / /   / /| |
            / /_/ / ____/ /_/ / _, _/ /___/ ___ |
            \____/_/    \____/_/ |_|\____/_/  |_|
E
Entong Shen 已提交
8 9 10 11 12 13
                  The Greenplum Query Optimizer
              Copyright (c) 2015, Pivotal Software, Inc.
            Licensed under the Apache License, Version 2.0
======================================================================
</pre>

14
Welcome to GPORCA, the Greenplum Next Generation Query Optimizer!
E
Entong Shen 已提交
15

16 17 18
GPORCA supports various build types: debug, release with debug info, release.
On x86 systems, GPORCA can also be built as a 32-bit or 64-bit library. You'll
need CMake 3.0 or higher to build GPORCA. Get it from cmake.org, or your
E
Entong Shen 已提交
19 20
operating system's package manager.

A
Atri Sharma 已提交
21 22 23
# First Time Setup

## Clone GPORCA
E
Entong Shen 已提交
24 25

```
X
Xin Zhang 已提交
26 27
git clone https://github.com/greenplum-db/gporca.git
cd gporca
E
Entong Shen 已提交
28 29 30 31
```

## Pre-Requisites

32
GPORCA uses the following libraries:
E
Entong Shen 已提交
33 34 35 36 37 38 39
1) GPOS - Greenplum's OS Abstraction Layer
2) GP-Xerces - Greenplum's patched version of Xerces-C 3.1.X

### Installing GPOS

[GPOS is available here](https://github.com/greenplum-db/gpos) The GPOS README
gives instructions for building and installing GPOS. Note that the build type
40
(e.g. DEBUG vs. RELEASE) for GPOS and GPORCA should match (mixing and matching
E
Entong Shen 已提交
41 42 43 44 45 46 47 48 49 50 51 52
can lead to errors).

### Installing GP-Xerces

To install GP-Xerces, obtain a copy of the
[Xerces-C source code](https://xerces.apache.org/xerces-c/download.cgi)
(versions 3.1.1 and 3.1.2 are tested and known to work) and apply the the GPDB
patchset (located at `patches/xerces-c-gpdb.patch` in the GP-Orca source tree)
before building. Presuming that you downloaded Xerces-C 3.1.2, a recipe for
building GP-Xerces would be something like the following:

```
X
Xin Zhang 已提交
53
wget http://archive.apache.org/dist/xerces/c/3/sources/xerces-c-3.1.2.tar.gz
O
oarap 已提交
54 55
tar -xzf xerces-c-3.1.2.tar.gz
cd xerces-c-3.1.2
A
Atri Sharma 已提交
56
patch -p1 < ../gporca/patches/xerces-c-gpdb.patch
O
oarap 已提交
57 58 59 60 61 62 63 64 65
mkdir build
cd build

# Use --prefix=/opt/gp_xerces if you don't want to override the default xerces
# However, this qp-xerces needs to be at default location /usr/local in order
# to build GPORCA
../configure 
make
sudo make install
E
Entong Shen 已提交
66 67
```

A
Atri Sharma 已提交
68
## Build GPORCA
69

E
Entong Shen 已提交
70
```
A
Atri Sharma 已提交
71 72 73 74 75
mkdir build
cd build
cmake ../
make
sudo make install
E
Entong Shen 已提交
76 77
```

A
Atri Sharma 已提交
78
# Advanced Setup
E
Entong Shen 已提交
79 80 81 82

## Preperation for build


83
Go into gporca and create a build folder
E
Entong Shen 已提交
84
```
O
oarap 已提交
85 86
mkdir build
cd build
E
Entong Shen 已提交
87 88 89 90 91 92 93 94 95 96
```

### How to generate make files with default options
Please ensure that build type of GPOS matches the version of Optimizer libraries
you are trying to build. Mixing and matching a DEBUG GPOS with a RELEASE Orca or
vice-versa may cause problems.

* debug build

```
O
oarap 已提交
97
cmake -D CMAKE_BUILD_TYPE=DEBUG ../
E
Entong Shen 已提交
98 99 100 101 102
```

* release build with debug info

```
O
oarap 已提交
103
cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo ../
E
Entong Shen 已提交
104 105 106 107 108
```

* release build

```
O
oarap 已提交
109
cmake -D CMAKE_BUILD_TYPE=RELEASE ../
E
Entong Shen 已提交
110 111 112 113
```

## Explicitly Specifying GPOS and GP-Xerces For Build

A
Atri Sharma 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
### GPOS

If GPOS was installed to the default location, the cmake build system for
GPORCA should find it automatically. Otherwise, cmake can be pointed to your
GPOS installation with the `GPOS_INCLUDE_DIR` and `GPOS_LIBRARY` options like
so:

```
cmake -D GPOS_INCLUDE_DIR=/opt/gpos/include -D GPOS_LIBRARY=/opt/gpos/lib/libgpos.so ..
```

Note that on Mac OS X, the library name will end with `.dylib` instead of `.so`.

### GP-XERCES

It is recommended to use the `--prefix` option to the Xerces-C configure script
to install GP-Xerces in a location other than the default under `/usr/local/`,
because you may have other software that depends on Xerces-C, and the changes
introduced in the GP-Xerces patch make it incompatible with the upstream
version. Installing in a non-default prefix allows you to have GP-Xerces
installed side-by-side with unpatched Xerces without incompatibilities.

You can point cmake at your patched GP-Xerces installation using the
`XERCES_INCLUDE_DIR` and `XERCES_LIBRARY` options like so:

However, to use the current build scripts in GPDB, Xerces with the gp_xerces
patch will need to be placed on the /usr path.

```
cmake -D XERCES_INCLUDE_DIR=/opt/gp_xerces/include -D XERCES_LIBRARY=/opt/gp_xerces/lib/libxerces-c.so ..
```

Again, on Mac OS X, the library name will end with `.dylib` instead of `.so`.

**Advanced - Cross-compiling 32-bit or 64-bit libraries** Unless you intend to
cross-compile a 32 or 64-bit version of GP-Orca, you can ignore these
instructions. If you need to explicitly compile for the 32 or 64-bit version of
your architecture, you need to set the `CFLAGS` and `CXXFLAGS` environment
variables for the configure script like so (use `-m32` for 32-bit, `-m64` for
64-bit):

```
CFLAGS="-m32" CXXFLAGS="-m32" ../configure --prefix=/opt/gp_xerces_32
```

### GPORCA

E
Entong Shen 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
As noted in the prerequisites section above, you may specify the
`GPOS_INCLUDE_DIR` and `GPOS_LIBRARY` options to tell cmake where to find
GPOS (or similarly with `XERCES_INCLUDE_DIR` and `XERCES_LIBRARY` for
GP-Xerces). These options are useful if GPOS/GP-Xerces is installed in a
nonstandard place, or if multiple versions are installed in different locations
(for instance DEBUG vs. RELEASE, or 32 vs. 64-bit builds).

For example:
```
cmake -D XERCES_INCLUDE_DIR=/opt/gp_xerces/include -D XERCES_LIBRARY=/opt/gp_xerces/lib/libxerces-c.so ../
```

## Advanced: Cross-Compiling 32-bit or 64-bit libraries

For the most part you should not need to explicitly compile a 32-bit or 64-bit
176 177 178 179 180
version of the optimizer libraries. By default, a "native" version for your host
platform will be compiled. However, if you are on x86 and want to, for example,
build a 32-bit version of Optimizer libraries on a 64-bit machine, you can do
so as described below. Note that you will need a "multilib" C++ compiler that
supports the -m32/-m64 switches, and you may also need to install 32-bit ("i386")
E
Entong Shen 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
versions of the C and C++ standard libraries for your OS. Finally, you will need
to build 32-bit or 64-bit versions of GPOS and GP-Xerces as appropriate.

Toolchain files for building 32 or 64-bit x86 libraries are located in the cmake
directory. Here is an example of building for 32-bit x86:

```
cmake -D CMAKE_TOOLCHAIN_FILE=../cmake/i386.toolchain.cmake ../
```

And for 64-bit x86:

```
cmake -D CMAKE_TOOLCHAIN_FILE=../cmake/x86_64.toolchain.cmake ../
```

## How to build

* build

```
O
oarap 已提交
202
make
E
Entong Shen 已提交
203 204 205 206 207
```

* for faster build use the -j option of make. For instance, the following command runs make on 7 job slots

```
O
oarap 已提交
208
make -j7
E
Entong Shen 已提交
209 210 211 212 213
```

* show all commands being run as part of make

```
O
oarap 已提交
214
make VERBOSE=1
E
Entong Shen 已提交
215 216 217 218
```

## How to test

219
To run all GPORCA tests, simply use the `ctest` command from the build directory
E
Entong Shen 已提交
220 221 222
after `make` finishes.

```
O
oarap 已提交
223
ctest
E
Entong Shen 已提交
224 225 226 227 228 229
```

Much like `make`, `ctest` has a -j option that allows running multiple tests in
parallel to save time. Using it is recommended for faster testing.

```
O
oarap 已提交
230
ctest -j7
E
Entong Shen 已提交
231 232 233 234 235 236 237
```

By default, `ctest` does not print the output of failed tests. To print the
output of failed tests, use the `--output-on-failure` flag like so (this is
useful for debugging failed tests):

```
O
oarap 已提交
238
ctest -j7 --output-on-failure
E
Entong Shen 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251
```

To run a specific individual test, use the `gporca_test` executable directly.

```
./server/gporca_test -U CAggTest
```

Note that some tests use assertions that are only enabled for DEBUG builds, so
DEBUG-mode tests tend to be more rigorous.

### Advanced: Extended Tests

252
Debug builds of GPORCA include a couple of "extended" tests for features like
E
Entong Shen 已提交
253 254 255 256 257 258 259
fault-simulation and time-slicing that work by running the entire test suite
in combination with the feature being tested. These tests can take a long time
to run and are not enabled by default. To turn extended tests on, add the cmake
arguments `-D ENABLE_EXTENDED_TESTS=1`.

## How to install

260
GPORCA has three libraries:
E
Entong Shen 已提交
261 262

1. libnaucrates --- has all DXL related classes, and statistics related classes
263 264 265
2. libgpopt     --- has all the code related to the optimization engine, meta-data accessor, logical / physical operators,
                    transformation rules, and translators (DXL to expression and vice versa).
3. libgpdbcost  --- cost model for GPDB.
E
Entong Shen 已提交
266

267
By default, GPORCA will be installed under /usr/local. You can change this by
E
Entong Shen 已提交
268 269
setting CMAKE_INSTALL_PREFIX when running cmake, for example:
```
O
oarap 已提交
270
cmake -D CMAKE_INSTALL_PREFIX=/home/user/gporca ../
E
Entong Shen 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
```

By default, the header files are located in:
```
/usr/local/include/naucrates
/usr/local/include/gpdbcost
/usr/local/include/gpopt
```
the library is located at:

```
/usr/local/lib/libnaucrates.so*
/usr/local/lib/libgpdbcost.so*
/usr/local/lib/libgpopt.so*
```

* build and install
```
O
oarap 已提交
289
make install
E
Entong Shen 已提交
290 291 292
```
* build and install with verbose output
```
O
oarap 已提交
293
make VERBOSE=1 install
E
Entong Shen 已提交
294 295
```

296
## Clean up stuff
E
Entong Shen 已提交
297 298 299

* remove the cmake files generated under build

300
* Remove gporca header files and library, (assuming the default install prefix /usr/local)
E
Entong Shen 已提交
301 302

```
O
oarap 已提交
303 304 305 306 307 308
rm -rf /usr/local/include/naucrates
rm -rf /usr/local/include/gpdbcost
rm -rf /usr/local/include/gpopt
rm -rf /usr/local/lib/libnaucrates.so*
rm -rf /usr/local/lib/libgpdbcost.so*
rm -rf /usr/local/lib/libgpopt.so*
309
```