当前位置:网站首页>Opengauss kernel: simple query execution

Opengauss kernel: simple query execution

2022-06-24 23:53:00 Huawei cloud developer Alliance

Abstract : This paper 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 .

This article is shared from Huawei cloud community 《openGauss Kernel analysis ( Two ): Simple query execution 》, author :Gauss Squirrel Club .

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_**yze_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 , 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 cleanup

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

Click to follow , The first time to learn about Huawei's new cloud technology ~

原网站

版权声明
本文为[Huawei cloud developer Alliance]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241834258424.html