Vector calculation method for rownum expression in OpenGauss
By executing the rownum expression vector calculation method in the query planning stage in the OpenGauss database, the problem that OpenGauss does not support the simultaneous use of column storage tables and rownum is solved, achieving more efficient query processing and performance improvement.
Patent Information
- Application Number
- CN202111429541.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-11-29
AI Technical Summary
OpenGauss database does not support the simultaneous use of column storage tables and rownum, resulting in low query efficiency and limited performance.
In the query plan execution phase of OpenGauss, the vector calculation method of rownum expression is implemented. By initializing and managing memory resources, a continuous integer sequence is generated, combined with the data of the column storage table for batch processing, and supporting the use of the rownum function.
Improved query efficiency and database performance, allowing OpenGauss to effectively use the rownum function during column storage table calculations.
Smart Images

Figure CN114036245B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of database management and operating system, and in particular relates to a vector calculation method for realizing rownum expressions in OpenGauss. Background Art
[0002] OpenGauss is an open source relational database management system. Its kernel is derived from PostgreSQL. As an open source and free database platform, it aims to encourage community contribution and cooperation. In a typical relational database management system such as OpenGauss, processing a query is usually divided into the following three stages:
[0003] (1) Lexical and grammatical analysis mainly converts the user's input text (SQL) into an internal data structure, generally called a grammar parse tree, and verifies the correctness of the grammar, ultimately obtaining a grammar parse tree representing SQL.
[0004] (2) Query optimization: The grammatical parsing tree obtained in the previous stage is optimized based on rules and physical costs to generate an optimal query plan.
[0005] (3) Execute the query plan generated in the previous stage (generally using an iterator), obtain the query results and return them to the user.
[0006] Currently, the OpenGauss database has implemented column storage and row storage. In a row storage table, the contents of the same row of records are logically stored in adjacent physical addresses; similarly, in a column storage table, the contents of several rows of records in the same column are also stored in adjacent physical addresses.
[0007] As we all know, column-stored tables are more suitable for OLAP (offline analytical processing) business, because such business is mainly for data statistics. In the calculation process, that is, in the above-mentioned stage (3), the contents of certain columns can be directly read in batches and calculated, thereby improving the disk IO efficiency. In order to adapt to this, in order to accelerate the calculation of these column-stored contents, OpenGauss uses vectorized calculation methods. For example, in the SQL such as select c1 from t where c1>10, t is stored in column storage. When this SQL executes the query plan, it will batch read a fixed number of c1 contents at a time, and then batch execute filtering greater than 10. This batch processing process is a vectorized calculation process, and finally the c1 that meets the conditions will be returned to the user one by one.
[0008] Rownum is a special expression, a pseudo output column, which generates a serialized number based on the returned record to mark the row number of the current output result, starting from 1 and increasing in sequence. With rownum, users can output some results that were originally difficult to complete, thereby better achieving the query purpose. However, the current OpenGauss database does not support the simultaneous use of column storage tables and rownum, which greatly limits the performance of the database and reduces query efficiency. Summary of the invention
[0009] In order to overcome the defect that the OpenGauss database does not support the simultaneous use of column storage tables and rownum, the present invention provides a solution. The present invention proposes for the first time a vector calculation method for realizing rownum expression in the query plan execution phase of OpenGauss, so that OpenGauss can also use the rownum function in the process of calculating the column storage table, thereby improving the query efficiency and helping to better exert the database performance.
[0010] The vector calculation method for realizing rownum expression in OpenGauss of the present invention aims to provide a vector calculation method capable of realizing rownum expression in the query plan stage of the OpenGauss database, so that the OpenGauss database can support the simultaneous use of column storage table and rownum, thereby improving the query efficiency and performance of the database;
[0011] The vector calculation method comprises the following steps:
[0012] (1) Initialize the context of the rownum expression that needs to be calculated, apply for memory resources that match the scale of this vector calculation to store the process of this vector calculation, and set the current rownum value to 1;
[0013] (2) According to the current rownum value and the vector space size N, the values from rownum to rownum+N-1 are placed into an array of length N and returned to the calling function;
[0014] (3) Destroy the context of the vector calculation and release memory resources.
[0015] Furthermore, step (2) of the method includes the following processing steps:
[0016] A. Open the next column storage file of the query start column in the column storage table to be queried. If the next column storage file does not exist, directly exit step (2);
[0017] B. Load a fixed number of N query start columns from the current column storage file position into a fixed memory area, and move the file pointer backward; if the current column storage file position is already at the end, jump to step A;
[0018] C. Starting from the current rownum value, generate N consecutive integers, put them into the fixed memory of the rownum value, and then increase the current rownum value by N;
[0019] D. Extract the next value from the fixed area that currently stores the query start column, and move the corresponding pointer back one position. If the current pointer position is already at the end, jump to step B, extract the next value from the fixed memory that stores the rownum value, and move its pointer back;
[0020] E. Combine the rownum value extracted in the previous step and the value of the query start column into a new column, return it to the user, and then jump to step D until the entire process is completed.
[0021] In addition, the present invention also relates to the use of the above-mentioned vector calculation method for realizing rownum expression in OpenGauss in OpenGauss database management or operating system.
[0022] In summary, the present invention proposes for the first time a vector calculation method for realizing rownum expression in the query planning stage of OpenGauss database, so that OpenGauss can also use the function of rownum in the calculation process of column storage table, overcoming the defect that OpenGauss database does not support the simultaneous use of column storage table and rownum in the past, improving query efficiency and helping to better exert database performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the following drawings are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0024] Figure 1 Schematic diagram of the implementation process of the vector calculation method of the present invention. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with specific embodiments. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. The present invention can also be implemented or applied through other different specific implementation methods. The details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention.
[0026] At the same time, it should be understood that the protection scope of the present invention is not limited to the specific embodiments described below; it should also be understood that the terms used in the embodiments of the present invention are for describing specific embodiments rather than for limiting the protection scope of the present invention.
[0027] Embodiment 1: A method for implementing vector calculation of rownum expression in the query plan execution stage of OpenGauss database, for example: for SQL: select rownum,c1 from t1, where t1 is a column storage table and c1 is the query start column. The purpose of this method is to extract the c1 column and number it sequentially. In the query plan execution stage, it is actually a process of sequentially scanning the t1 table.
[0028] The method comprises the following steps:
[0029] (1) Initialize the context of the rownum expression that needs to perform vector calculation, apply for memory resources that match the scale of this vector calculation to store the process of this vector calculation, and set the current rownum value to 1.
[0030] (2) According to the current rownum value and the vector space size N, the values from rownum to rownum+N-1 are placed into an array of length N and returned to the calling function. The specific processing includes the following:
[0031] A. Open the next column storage file of c1 in table t1. If the next column storage file does not exist, exit step (2) directly.
[0032] B. Load a fixed number N of c1 column values from the current column storage file position into a fixed memory area and move the file pointer backwards; if the current column storage file position is already at the end, jump to step A;
[0033] C. Starting from the current rownum value, generate N consecutive integers, put them into the fixed memory of the rownum value, and then increase the current rownum value by N;
[0034] D. Extract the next value from the fixed area currently storing c1, and move the corresponding pointer back one position. If the current position of the pointer is already at the end, jump to step B, extract the next value from the fixed memory storing the rownum value, and move its pointer back;
[0035] E. Combine the rownum value extracted in the previous step and the value of c1 into a new column, return it to the user, and then jump to step D until the entire process is completed.
[0036] (3) Destroy the context of the vector calculation and release memory resources.
[0037] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, replacement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A vector calculation method for implementing rownum expression in OpenGauss, characterized in that: This method provides a vector calculation method that can realize rownum expression in the query plan execution phase of OpenGauss database, so that OpenGauss database can support the use of column storage table and rownum at the same time; The vector calculation method comprises the following steps: (1) Initialize the context of the rownum expression that needs to be calculated, apply for memory resources that match the scale of this vector calculation to store the process of this vector calculation, and set the current rownum value to 1; (2) According to the current rownum value and the vector space size N, the values from rownum to rownum+N-1 are placed into an array of length N and returned to the calling function; this includes the following processing steps: A. Open the next column storage file of the query start column in the column storage table to be queried. If the next column storage file does not exist, directly exit step (2). B. Load a fixed number of N query start columns from the current column storage file position into a fixed memory area and move the file pointer backwards; if the current column storage file position is already at the end, jump to step A; C. Generate N consecutive integers starting from the current rownum value, put them into the fixed memory of the rownum value, and then increment the current rownum value by N; D. Extract the next value from the fixed area that currently stores the query start column, and move the corresponding pointer back one position. If the current pointer position is already at the end, jump to step B, extract the next value from the fixed memory that stores the rownum value, and move its pointer back; E. Combine the rownum value extracted in the previous step and the value of the query start column into a new column, return it to the user, and then jump to step D until the entire process ends; (3) Destroy the context of the vector calculation and release memory resources.
2. Use of the vector calculation method for realizing rownum expression in OpenGauss as claimed in claim 1 in OpenGauss database management or operating system.
