当前位置:网站首页>Analysis of the execution process of opengauss simple query SQL

Analysis of the execution process of opengauss simple query SQL

2022-06-11 15:40:00 Gauss squirrel Club

Catalog

Simple query execution

gdb debugging


Last issue Cool guy analyzed openGauss Database startup process , Including the main thread , Starting process of auxiliary thread and business processing thread , This issue mainly analyzes the application of simple query statements in business processing threads Postgres Execution process on , And how to use gdb Sort out the logic of the code .

Simple query execution

SQL The engine is the portal to the database system , The entry function to execute the user's simple query is exec_simple_query. Running on the business processing thread Postgres.

You can usually SQL The engine is divided into SQL Parsing and query optimization are two main modules ,SQL Engine response to input SQL Lexical analysis of language 、 Syntax analysis 、 Semantic analysis , To generate a logical execution plan , After algebraic optimization and cost optimization, the logical execution plan , Generate physical execution plan .

stay SQL After the engine optimizes the user's query parsing into an executable plan , The database enters the query execution phase . The actuator extracts relevant data based on the execution plan 、 operation 、 to update 、 Delete and other operations , In order to achieve the purpose of user query .

 exec_simple_query

1.start_xact_command(): Start a transaction

2.pg_parse_query(): Lexical and grammatical analysis of query statements , Generate one or more initial parsing trees

3.  Get into foreach (parsetree_item, parsetree_list) loop , Execute a query on each parse tree

4. pg_analyze_and_rewrite(): Based on the syntax analysis tree, generate Query Logical query tree of data structure , And perform operations such as rewriting

5. pg_plan_queries(): Optimize the logical query tree , Generate query plan

6. CreatePortal(): establish Portal, Portal Is to perform SQL The carrier of sentence , Every one of them SQL Corresponding to the only Portal

7. PortalStart(): Responsible for Portal Structure Initialization work , Including operator initialization Memory context allocation, etc

8. PortalRun() Responsible for real execution and computation , it Is the core of the actuator

9. PortalDrop(): Responsible for the final clean-up , Mainly data structure 、 cache Clean-up

10. finish_xact_command(): Complete transaction commit

11. EndCommand(): Notify the client that the query execution is complete

gdb debugging

Debugging requires symbol information ,configure Use the following command

./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib

gdb attach Process number , The process number here is 17012

gdb attach 17012

 info threads See all threads ,t Thread number switch thread ,bt You can view the thread call stack

You can also use linux Tools gstack Print function call stack

To debug select Statements, for example ,gdb attach  Process number , stay exec_simple_query Set a breakpoint , perform select Statement to start debugging

原网站

版权声明
本文为[Gauss squirrel Club]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111535102331.html