Download presentation
Presentation is loading. Please wait.
Published byAnis Harrell Modified over 9 years ago
1
Query Planner Daniel Antwi http://www.site.uottawa.ca/~dantw005/csi3130/ CSI 3130 – 2012 – Lab 6
2
Outline Query Planner: The Big Picture Modify Source Codes
3
PostgreSQL multiuser database server postmaster is the PostgreSQL multiuser database server. In order for a client application to access a database it connects to a running postmaster. The postmaster then starts a separate server process postgres to handle the connection. The postmaster also manages the communication among server processes.
6
Planner/Optimizer The task of the planner/optimizer is to create an optimal execution plan. – Scan methods seqscan, index scan... – Join methods nested loop join, merge join, hash join – Join order for more than two relations
15
Modify Planner Source Codes We will modify PostgreSQL source codes – query planner Under: – src/backend/optimizer – src/backend/optimizer/plan – src/backend/optimizer/path
16
Modify the Code: Example Add the debug maro – Edit "src/backend/optimizer/plan/planner.c“ and “src/backend/optimizer/path/allpaths.c” – Add “#define OPTIMIZER_DEBUG” Edit “/src/backend/optimizer/util/pathnode.c” – After line: 405, add one line pathnode->total_cost=0; – Make install again – Start the server and try explain select * from cust where cid=100;
17
Debug using GDB Start GDB – gdb./postgres Set breakpoints – break pathnode.c:402 Start the server in single-user mode – start --single -D../data postgres – continue Execute a SQL – explain select * from cust where cid=100; – (break at the breakpoint in pathnode.c) Track – backtrace (see the calling stack) – step 1 (track step by step) – continue
18
Related Files src/backend/optimizer/plan/planmain.c src/backend/optimizer/path/allpaths.c – set_plain_rel_pathlist set_plain_rel_pathlist src/backend/optimizer/path/costsize.c src/backend/optimizer/path/pathkeys.c src/backend/optimizer/plan/createplan.c src/backend/optimizer/README – Optimizer Data Structure – PathKeys
19
Related Source Codes src/backend/optimizer/plan/planmain.c – Line 85: query_planner() Generate a plan src/backend/optimizer/plan/allpaths.c – Line 86: make_one_relation() Find all paths to generate a result relation – Line 166: set_rel_pathlist() – Line 214: set_plain_rel_pathlist() Build paths for a base relation /src/backend/optimizer/util/pathnode.c – Line 397: create_seqscan_path()
20
Get Details of Plans In PSQL use EXPLAIN VERBOSE From server: – use “--log-error-verbosity=verbose -d5” Enable OPTIMIZER_DEBUG – Add the following line at the beginning of "src/backend/optimizer/plan/planner.c“ and “src/backend/optimizer/path/allpaths.c” – #define OPTIMIZER_DEBUG – And then make install again Try the queries from the last lab – example example
21
List of Commands - Installation cd postgresql-9.0.2./configure --enable-debug --enable-cassert --enable-depend -- prefix=/home/rwchen/pginstall Make Build PostgreSQL $gmake Wait for this message: All of PostgreSQL successfully made. Ready to install. Install Install PostgreSQL to $HOME/pginsall directory $make install Wait for this message: PostgreSQL installation complete. Change to your own directory (use pwd to get current path)
22
List of Commands - GDB gdb./postgres break pathnode.c:402 start --single -D../data postgres continue backtrace step 1 cd../pginstall/bin./initdb –D../data./postgres –D../data –p 5678./psql postgres –p 5678./postgres --single –D../data postgres (use Ctrl+D to exit) Change to a random port number to avoid conflicts Single-user mode
23
GDB reference card – http://users.ece.utexas.edu/~adnan/gdb- refcard.pdf http://users.ece.utexas.edu/~adnan/gdb- refcard.pdf vi reference card – http://www.digilife.be/quickreferences/QRC/Vi%2 0Reference%20Card.pdf http://www.digilife.be/quickreferences/QRC/Vi%2 0Reference%20Card.pdf
24
Reference Chap. 43.5. Planner/Optimizer – http://www.postgresql.org/docs/8.4/interactive/p lanner-optimizer.html http://www.postgresql.org/docs/8.4/interactive/p lanner-optimizer.html Chap 17.3. Starting the Database Server – http://www.postgresql.org/docs/8.4/interactive/s erver-start.html http://www.postgresql.org/docs/8.4/interactive/s erver-start.html PostgreSQL Internals Presentation – http://www.postgresql.org/files/developer/intern alpics.pdf http://www.postgresql.org/files/developer/intern alpics.pdf
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.