Method, system and equipment for creating predefined query instruction PLSQLUNIT based on openGauss database

By identifying and replacing predefined query instructions in the openGauss database, symbol conflicts and missing functions are resolved, compatibility with Oracle and efficient SQL and PLSQL development are achieved, migration costs are reduced, and development efficiency and code readability are improved.

CN120803425APending Publication Date: 2025-10-17BEIJING VASTDATA TECH
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510977687.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-16
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

The openGauss database lacks support for predefined query instructions, resulting in compatibility issues, symbol resolution conflicts, and missing functions when migrating from Oracle, affecting the convenience and efficiency of SQL and PLSQL development.

Method used

During the lexical parsing phase, predefined query instructions starting with $$ are identified. Compilation unit information is obtained through functions, symbol conflicts are resolved, and constants are replaced from compilation information and database metadata during the syntax processing phase. The $$PLSQL_UNIT function is created to obtain the compilation unit name.

Benefits of technology

It improves the migration convenience from Oracle to openGauss, reduces code adjustment costs, enhances development efficiency, simplifies code writing and maintenance, ensures compatibility and code readability, and provides a more efficient database usage experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803425A_ABST
    Figure CN120803425A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of database management, and provides a predefined query instruction PLSQLUNIT creating method, system and equipment based on an openGauss database, and the method comprises the following steps: in a lexical analysis stage, identifying a predefined query instruction from the beginning; in the grammar processing stage, a predefined query instruction is recognized as an expression, and corresponding content constants are obtained from compilation information and database metadata for replacement; and creating a function corresponding to the predefined query instruction PLSQLUNIT, and obtaining compiling unit information through the function. According to the method, the migration convenience from the Oracle to the openGauss can be improved; the code adjustment cost is reduced, the development efficiency of the SQL and the PLSQL is enhanced, and the code writing and maintenance work is simplified; the problem of parsing conflict of symbols is solved, and the compatibility with original functions of openGauss is ensured; the name of the current compiling unit is dynamically acquired during compiling, and the code readability and the operation efficiency are optimized; and through a predefined query instruction compatible with Oracle, good ecological compatibility is kept.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database management, and particularly relates to a pre-defined query instruction $$PLSQL_UNIT creation method and system based on an openGauss database and equipment. BACKGROUND

[0002] In the field of database management systems, especially in relational databases, SQL and PLSQL (Procedural SQL) are the core languages for implementing data operations and program logic. Oracle database, as a widely used database system in the industry, provides strong support for SQL and PLSQL, including various pre-defined query instructions (such as $$PLSQL_UNIT). These instructions can determine their values at compile time, thereby simplifying SQL writing methods and improving compilation efficiency. For example, the $$PLSQL_UNIT instruction can obtain the name of the object unit where the current execution instruction is located, which is of great significance to code debugging, log recording, and dynamic SQL generation scenarios.

[0003] However, with the development of technology and the diversification of user needs, more and more users hope to obtain similar development experience and functional support as Oracle in other database systems. openGauss database, as a high-performance and highly available open-source relational database, has received widespread attention in recent years. However, in terms of pre-defined query instruction support, openGauss database has some deficiencies, which limit the convenience of users migrating from Oracle to openGauss.

[0004] Specifically, the openGauss database in the prior art has the following main problems when processing pre-defined query instructions similar to $$: 1. Compatibility problem: Oracle database supports various pre-defined query instructions (such as $$PLSQL_UNIT), which can determine their values at compile time, thereby simplifying SQL writing methods and improving compilation efficiency. However, openGauss database does not support such pre-defined query instructions natively, which makes users migrating from Oracle to openGauss need to adjust the code, increasing the migration cost.

[0005] 2. Symbol parsing conflict: In openGauss, the $$ symbol is used as the starting point identifier of the PLSQL block, which is easy to conflict with the $$ prefix of the pre-defined query instruction, causing the inability to correctly distinguish the purposes of the two. This conflict makes it difficult to accurately identify the pre-defined query instruction in the lexical analysis phase, thereby affecting the subsequent compilation process.

[0006] 3. Function loss: openGauss database lacks support for predefined query instructions, and cannot obtain object unit name, owner, row number and other information at compile time like Oracle. This not only limits the convenience of users when writing complex SQL and PLSQL code, but also may cause some functions that rely on predefined query instructions to be unable to implement.

[0007] Chinese patent CN117909355A discloses a database query instruction generation method, device, computer equipment and storage medium. The scheme generates SQL statements through natural language, but does not support predefined query instructions such as $$PLSQL_UNIT. This support is very important for users migrating from Oracle and other databases to new databases, because predefined query instructions play an important role in code debugging, logging and other scenarios.

[0008] How to meet the needs of users migrating from Oracle to openGauss and improve the functional integrity of openGauss database in SQL and PLSQL development has become a technical problem to be solved. SUMMARY

[0009] Therefore, in order to overcome the shortcomings of the prior art, the present application aims to provide a predefined query instruction $$PLSQL_UNIT creation method and system based on openGauss database and equipment.

[0010] According to a first aspect of the present application, a predefined query instruction $$PLSQL_UNIT creation method based on openGauss database is provided, which comprises: Step S1: in the lexical analysis stage, identify the predefined query instruction starting with $$; Step S2: in the syntax processing stage, identify the predefined query instruction as an expression, and replace the corresponding content constant from the compilation information and database metadata; Step S3: create a function corresponding to the predefined query instruction $$PLSQL_UNIT, and obtain the compilation unit information through the function.

[0011] Optionally, the predefined query instruction $$PLSQL_UNIT creation method based on openGauss database comprises: Configure a lexical rule that matches the $$xxx form string and its corresponding action, and distinguish the predefined query instruction starting with $$ and the $$ symbol in the action of the lexical rule; For a predefined query instruction starting with $$, a token representing the predefined query instruction is returned, and the value of the token is the predefined query instruction string; For a non-predefined query instruction starting with $$, the $$ symbol is returned, and the character content after the $$ symbol is returned to the buffer for re-parsing during the next lexical processing.

[0012] Optionally, the method for creating a predefined query instruction $$PLSQL_UNIT based on an openGauss database according to the present application, step S2 includes: in the compilation process of the PLSQL block, parsing and checking expressions in the PLSQL syntax and the SQL syntax, for expressions identified as predefined query instructions, obtaining corresponding content constants from the compilation information and the metadata of the database, and replacing them in the expressions.

[0013] Optionally, the method for creating a predefined query instruction $$PLSQL_UNIT based on an openGauss database according to the present application, step S2 includes: when an expression of a predefined query instruction is identified from the PLSQL syntax, adding processing logic for a token representing a predefined query instruction in the read_sql_construct6 function, calling a corresponding processing function according to the value of the token, obtaining a constant value string returned by the processing function, and concatenating the constant value string into the expression string.

[0014] Optionally, the method for creating a predefined query instruction $$PLSQL_UNIT based on an openGauss database according to the present application, step S2 includes: When an expression of a predefined query instruction is identified from the SQL syntax, adding processing logic for a token representing a predefined query instruction in the make_execsql_stmt function; According to the value of the token representing the predefined query instruction, a corresponding processing function is called, a constant value string returned by the processing function is obtained, and the constant value string is concatenated into the expression string.

[0015] Optionally, the method for creating a predefined query instruction $$PLSQL_UNIT based on an openGauss database according to the present application, step S3 includes: creating a function get_inquiry_directive_plsql_unit in the syntax module of the PLSQL, and in the function, obtaining the unit name according to the compilation state information stored in the memory during the compilation of the PLSQL program.

[0016] Optionally, the method for creating the predefined query instruction $$PLSQL_UNIT based on the openGauss database according to the present application, step S3, comprises: checking the compilation state of the current compilation unit, and returning the name of the package if the current compilation is a package; checking whether the current compilation function is a subprogram if the current compilation is a function, recursively finding the top-level parent program of the subprogram, and taking the top-level parent program as the compilation unit if the current compilation function is a subprogram, or taking the current compilation function as the compilation unit if the current compilation function is not a subprogram.

[0017] Optionally, the method for creating the predefined query instruction $$PLSQL_UNIT based on the openGauss database according to the present application, step S3, further comprises: identifying the type of the current compilation unit, and returning the name of the package, trigger or object type if the type of the current compilation unit is a package, object type or trigger function; returning a null value if the type of the current compilation unit is an anonymous block; or returning the name of the function or stored procedure if the type of the current compilation unit is a function or stored procedure.

[0018] According to a second aspect of the present application, a system for creating a predefined query instruction $$PLSQL_UNIT based on an openGauss database is provided, which comprises a creation server, and the creation server comprises: an identification module configured to identify the predefined query instruction starting with $$ in a lexical analysis stage; a replacement module configured to replace the predefined query instruction as an expression in a syntax processing stage, and replace the corresponding content constant obtained from the compilation information and the database metadata; a creation module configured to create a function corresponding to the predefined query instruction $$PLSQL_UNIT, and obtain the compilation unit information through the function.

[0019] According to a third aspect of the present application, a computer device is provided, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the method according to the first aspect of the present application when executing the program.

[0020] The application is based on an openGauss database pre-defined query instruction $$PLSQL_UNIT creation method and system and device, which significantly improves the migration convenience from Oracle to openGauss; reduces the code adjustment cost, enhances the development efficiency of SQL and PLSQL, simplifies the code writing and maintenance work; solves the analysis conflict problem of $$ symbol, ensures the compatibility with the original function of openGauss; supports dynamic acquisition of the current compilation unit name at compile time, optimizes the code readability and running efficiency; through the compatibility of the pre-defined query instruction of Oracle, the good ecological compatibility is maintained, and a more efficient and more convenient database use experience is provided for users. BRIEF DESCRIPTION OF DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.

[0022] Figure 1 An architecture example diagram of a pre-defined query instruction $$PLSQL_UNIT creation system based on an openGauss database according to an embodiment of the present application; Figure 2 An architecture example diagram of a pre-defined query instruction $$PLSQL_UNIT creation system based on an openGauss database according to an embodiment of the present application; Figure 3 A step flowchart of a pre-defined query instruction $$PLSQL_UNIT creation method based on an openGauss database according to an embodiment of the present application; Figure 4 An execution flowchart example diagram of a pre-defined query instruction $$PLSQL_UNIT creation method based on an openGauss database according to an embodiment of the present application; Figure 5 A structure schematic diagram of the device provided by the present application. DETAILED DESCRIPTION

[0023] The embodiments of the present application will be described in detail below with reference to the drawings.

[0024] It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict; and all other embodiments obtained by those skilled in the art on the basis of the embodiments in the present disclosure without creative labor belong to the scope of protection of the present disclosure.

[0025] It is to be appreciated that various aspects of the embodiments described below are presented in terms of sequences of actions or events. It should be appreciated, however, that the descriptions, embodiments, and examples are illustrative in nature and are not intended to be limiting. Against the background of this disclosure, those skilled in the art will appreciate that one aspect described herein can be implemented independently of any other aspects, and that two or more of these aspects can be combined in any suitable manner. For example, an apparatus can be implemented or a method can be practiced using any number of the aspects set forth herein. In addition, such an apparatus can be implemented or such a method can be practiced using other structure and / or functionality in addition to or other than one or more of the aspects set forth herein.

[0026] Figure 1 An example diagram of an architecture of a system for creating a predefined query instruction $$PLSQL_UNIT based on an openGauss database according to an embodiment of the present application is shown in FIG. 1. As shown in FIG. 1, the system can include a creating server 101, a communication network 102, and / or one or more creating clients 103. Figure 1 As an example, the system includes a plurality of creating clients 103. Figure 1 As an example, the system includes a plurality of creating clients 103.

[0027] The creating server 101 can be any suitable server for storing information, data, programs, and / or any other suitable type of content. In some embodiments, the creating server 101 can perform suitable functions. For example, in some embodiments, the creating server 101 can be used to create a predefined query instruction $$PLSQL_UNIT based on an openGauss database. As an optional example, in some embodiments, the creating server 101 can be used to: in a lexical analysis phase, identify a predefined query instruction starting with $$; in a syntax processing phase, identify the predefined query instruction as an expression, and replace corresponding content constants from compilation information and database metadata; create a function corresponding to the predefined query instruction $$PLSQL_UNIT, through which compilation unit information is obtained.

[0028] Figure 2 An example diagram of an architecture of a creating server of a system for creating a predefined query instruction $$PLSQL_UNIT based on an openGauss database according to an embodiment of the present application is shown in FIG. 2. As shown in FIG. 2, in this embodiment, the creating server includes: Figure 2 As shown in FIG. 2, in this embodiment, the creating server includes: a recognition module configured to, in a lexical analysis phase, identify a predefined query instruction starting with $$; a replacement module configured to, in a syntax processing phase, identify the predefined query instruction as an expression, and replace corresponding content constants from compilation information and database metadata; The creation module creates a function corresponding to the predefined query instruction $$PLSQL_UNIT, and obtains the compilation unit information through the function.

[0029] As another example, in some embodiments, the creation service 101 can send the predefined query instruction $$PLSQL_UNIT creation method based on the openGauss database to the creation client 103 for user use according to the request of the creation client 103.

[0030] As an optional example, in some embodiments, the creation client 103 is configured to provide a visual creation interface for receiving a selection input operation of a user for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database, and for obtaining and displaying a creation interface corresponding to an option selected by the selection input operation from the creation service 101 in response to the selection input operation, the creation interface at least displaying information for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database and operation options for the information for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database.

[0031] In some embodiments, the communication network 102 can be any suitable combination of one or more wired and / or wireless networks. For example, the communication network 102 can include any one or more of the following: the Internet, an intranet, a wide-area network (WAN), a local-area network (LAN), a wireless network, a digital subscriber line (DSL) network, a frame relay network, an asynchronous transfer mode (ATM) network, a virtual private network (VPN), and / or any other suitable communication network. The creation client 103 can connect to the communication network 102 through one or more communication links (e.g., communication link 104), which can link to the creation service 101 via one or more communication links (e.g., communication link 105). The communication links can be any communication links suitable for communicating data among the creation client 103 and the creation service 101, such as network links, dial-up links, wireless links, hard-wired links, any other suitable communication links, or any suitable combination of such links.

[0032] The creation client 103 can include any one or more clients that present interfaces related to high-speed access ORC external tables in a suitable form for user use and operation. In some embodiments, the creation client 103 can include any suitable type of device. For example, in some embodiments, the creation client 103 can include a mobile device, a tablet computer, a laptop computer, a desktop computer, and / or any other suitable type of client device.

[0033] Although the creation service end 101 is illustrated as one device, in some embodiments, any appropriate number of devices can be used to perform the functions performed by the creation service end 101. For example, in some embodiments, multiple devices can be used to implement the functions performed by the creation service end 101. Alternatively, the functions of the creation service end 101 can be implemented using a cloud service.

[0034] Based on the above system, the embodiment of the application provides a pre-defined query instruction $$PLSQL_UNIT creation method based on an openGauss database, which is described below through the following embodiments.

[0035] Figure 3 A step flowchart of a pre-defined query instruction $$PLSQL_UNIT creation method based on an openGauss database according to an embodiment of the application. Figure 4 A pre-defined query instruction $$PLSQL_UNIT creation method based on an openGauss database according to an embodiment of the application is shown in the execution flowchart example. Figure 3 And Figure 4 As shown in the pre-defined query instruction $$PLSQL_UNIT creation method based on an openGauss database, the method can be executed on a creation service end, and the method includes the following steps: Step S1: In the lexical analysis stage, identify the pre-defined query instruction starting with $$.

[0036] In this embodiment, a lexical rule matching the $$xxx form string and its corresponding action is configured, and in the action of the lexical rule, the pre-defined query instruction starting with $$ and the $$ symbol are distinguished; for the pre-defined query instruction starting with $$, a token representing the pre-defined query instruction is returned, and the value of the token is the pre-defined query instruction string; for the non-pre-defined query instruction starting with $$, the $$ symbol is returned, and the character content after the $$ symbol is returned to the buffer for re-parsing in the next lexical processing.

[0037] In the openGauss database, the $$ symbol is originally used as the starting point identifier of the PLSQL block, which conflicts with the prefix of the pre-defined query instruction. In this embodiment, a new rule is added in the lexical analysis stage, and the $$ symbol of the pre-defined query instruction and the starting point of the PLSQL block are distinguished by the longest and first matching principle, effectively solving the conflict problem. This design not only ensures the correct identification of the pre-defined query instruction, but also maintains the normal operation of the original function of the openGauss database, avoiding compatibility damage to the existing code.

[0038] Step S2: In the syntax processing stage, the predefined query instruction is identified as an expression, and the corresponding content constant is obtained from the compilation information and database metadata for replacement.

[0039] In the compilation process of the PLSQL block, the expressions in the PLSQL syntax and the SQL syntax are parsed and checked. For the expression identified as the predefined query instruction, the corresponding content constant is obtained from the compilation information and the metadata of the database, and is replaced in the expression.

[0040] As an optional embodiment, when the expression of the predefined query instruction is identified from the PLSQL syntax, the processing logic of the token (such as DOUBLE_DOLLAR_IDENT) representing the predefined query instruction is added in the read_sql_construct6 function. According to the value of the token, the corresponding processing function is called to obtain the constant value string returned by the processing function, and the constant value string is spliced into the expression string. When the expression of the predefined query instruction is identified from the SQL syntax, the processing logic of the token representing the predefined query instruction is added in the make_execsql_stmt function. According to the value of the token representing the predefined query instruction, the corresponding processing function is called to obtain the constant value string returned by the processing function, and the constant value string is spliced into the expression string.

[0041] The value of the predefined query instruction is determined at compile time, which means that these instructions can be replaced with specific content constants in the syntax processing stage, thereby reducing the computational overhead at runtime. The embodiment parses and replaces the predefined query instruction in the syntax processing stage, so that the generated PLSQL and SQL code is more efficient, improves the overall compilation efficiency, and also lays the foundation for runtime performance optimization. For example, $$PLSQL_UNIT can dynamically obtain the name of the current compilation unit, which is of great significance to code debugging, log recording, and dynamic SQL generation. By implementing this function in openGauss, users can more efficiently write and maintain complex SQL and PLSQL code, reduce repetitive work, and improve development efficiency.

[0042] Step S3: Create a function corresponding to the predefined query instruction $$PLSQL_UNIT to obtain the compilation unit information through the function.

[0043] In the embodiment, a function get_inquiry_directive_plsql_unit is created in the syntax module of the PLSQL, and the unit name is obtained in the function according to the compilation state information stored in the memory during the compilation of the PLSQL program.

[0044] As an optional example, in this embodiment, the compilation state of the current compilation unit is checked, and if the current compilation is a package, the name of the package is returned; if the current compilation is a function, it is checked whether the currently compiled function is a subprogram, if it is a subprogram, the top-level parent program of the subprogram is recursively found, and the top-level parent program is taken as the compilation unit, if the current compilation function is not a subprogram, the currently compiled function is taken as the compilation unit. The type of the current compilation unit is identified, if the type of the current compilation unit is a package, an object type or a trigger function, the name of the package, trigger or object type is returned; if the type of the current compilation unit is an anonymous block, an empty value is returned; if the current compilation unit is a function or a stored procedure, the name of the function or the stored procedure is returned.

[0045] By implementing the $$PLSQL_UNIT instruction, users can dynamically obtain the name of the current compilation unit at compile time, including anonymous blocks, functions, stored procedures, packages, triggers and object types, etc. This function has important value for dynamically generating SQL statements, implementing code self-description and performing runtime context awareness, etc. For example, in log recording, the name of the currently executed PLSQL unit can be dynamically recorded, facilitating problem positioning and troubleshooting.

[0046] The embodiment solves the problem of code adjustment caused by the incompatibility of the predefined query instruction when migrating from an Oracle database to an openGauss database. By supporting the $$PLSQL_UNIT predefined query instruction, users do not need to make a large number of modifications to the original PLSQL code developed based on Oracle, significantly reducing the migration cost and workload, improving the migration efficiency, enabling the openGauss database to better meet the needs of users migrating from Oracle, and expanding its applicable scope in the market. The introduction of the predefined query instruction makes the SQL and PLSQL code more concise and easy to read. In Oracle, developers are used to using instructions such as $$PLSQL_UNIT to obtain relevant information about the current execution environment, thereby achieving more flexible logic control. This embodiment implements similar functions in openGauss, enabling users to directly use these instructions in the code without the need to obtain the same information through complex queries or other means, not only improving the readability of the code, but also facilitating subsequent maintenance and management. While implementing the predefined query instruction $$PLSQL_UNIT, this embodiment fully considers compatibility with Oracle databases. By compatible with the syntax and semantics of the predefined query instruction of Oracle, users can continue to use their original development habits and code logic after migrating to openGauss without the need for additional learning and adjustment. This compatibility not only reduces the migration resistance of users, but also enables openGauss to better integrate into the existing Oracle ecosystem.

[0047] In practical applications, the pre-defined query instruction $$PLSQL_UNIT creation method and system based on the openGauss database of the embodiment can improve the convenience of Oracle to openGauss migration; reduce the code adjustment cost, enhance the development efficiency of SQL and PLSQL, simplify the code writing and maintenance work; solve the analysis conflict problem of the $$ symbol, ensure the compatibility with the original function of openGauss; support dynamic acquisition of the current compilation unit name at compile time, optimize the code readability and running efficiency; through the compatibility of the pre-defined query instruction of Oracle, maintain good ecological compatibility, and provide users with more efficient and more convenient database use experience.

[0048] As shown in Figure 5 The application further provides a device, including a processor 210, a communication interface 220, a memory 230 for storing a processor-executable computer program, and a communication bus 240. The processor 210, the communication interface 220, and the memory 230 can communicate with each other through the communication bus 240. The processor 210 can realize the pre-defined query instruction $$PLSQL_UNIT creation method based on the openGauss database by running the executable computer program.

[0049] The computer program in the memory 230 can be implemented in the form of a software function unit and sold or used as an independent product. When stored in a computer-readable storage medium, the computer program can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the application essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device) to execute all or part of the steps of the embodiments of the application. The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various program code storage media.

[0050] The system embodiments described above are only schematic, and the units described as separate units can be or can not be physically separated, and the units shown as units can be or can not be physical units, that is, they can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiments based on actual needs. Those skilled in the art can understand and implement without creative labor.

[0051] Those skilled in the art can clearly understand the implementation of the embodiments by the description of the above embodiments, and the embodiments can be implemented by means of software and necessary universal hardware platforms, and of course, can also be implemented by hardware. Based on such understanding, the above technical solutions can be embodied in the form of a software product, and the computer software product can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the method of each embodiment or some parts of the embodiment.

[0052] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database, characterized in that: The method comprises: Step S1: In the lexical parsing stage, identify predefined query instructions starting with $$; Step S2: In the syntax processing stage, the predefined query instruction is identified as an expression, and the corresponding content constant is obtained from the compilation information and database metadata for replacement; Step S3: Create a function corresponding to the predefined query instruction $$PLSQL_UNIT, and obtain the compilation unit information through the function.

2. The method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database according to claim 1, characterized in that: Step S1 includes: Configure a lexical rule that matches strings of the $$xxx format and its corresponding actions. In the actions of this lexical rule, distinguish between predefined query instructions starting with $$ and the $$ symbol. For predefined query instructions that start with $$, return the token representing the predefined query instruction. The value of the token is the predefined query instruction string. For non-predefined query instructions starting with $$, the $$ symbol is returned, and the character content after the $$ symbol is returned to the buffer, waiting to be re-parsed during the next lexical processing.

3. The method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database according to claim 1, characterized in that: Step S2 includes: during the compilation process of the PLSQL block, parsing and checking expressions in the PLSQL syntax and the SQL syntax, and for expressions identified as predefined query instructions, obtaining corresponding content constants from the compilation information and metadata of the database, and replacing them into the expressions.

4. The method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database according to claim 3, characterized in that: Step S2 includes: when an expression of a predefined query instruction is identified from the PLSQL syntax, processing logic for the token representing the predefined query instruction is added to the read_sql_construct6 function, a corresponding processing function is called according to the value of the token, a constant value string returned by the processing function is obtained, and the constant value string is spliced ​​into the expression string.

5. The method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database according to claim 3, characterized in that: Step S2 includes: When identifying the expression of the predefined query instruction from the SQL grammar, add the processing logic of the token representing the predefined query instruction in the make_execsql_stmt function; The corresponding processing function is called according to the value of the token representing the predefined query instruction, the constant value string returned by the processing function is obtained, and the constant value string is concatenated into the expression string.

6. The method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database according to claim 1, characterized in that: Step S3 includes: creating a function get_inquiry_directive_plsql_unit in the grammar module of PLSQL, and obtaining the unit name in the function according to the compilation status information stored in the memory during the compilation of the PLSQL program.

7. The method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database according to claim 1, characterized in that: Step S3 includes: checking the compilation status of the current compilation unit, and if the current compilation is a package, returning the package name; if the current compilation is a function, checking whether the current compilation function is a subroutine, and if it is a subroutine, recursively finding the top-level parent program of the subroutine, and using the top-level parent program as the compilation unit; if the current compilation function is not a subroutine, using the current compilation function as the compilation unit.

8. The method for creating a predefined query instruction $$PLSQL_UNIT based on the openGauss database according to claim 1, characterized in that: Step S3 also includes: identifying the type of the current compilation unit, and if the type of the current compilation unit is a package, an object type, or a trigger function, returning the name of the package, trigger, or object type; if the type of the current compilation unit is an anonymous block, returning a null value; if the current compilation unit is a function or a stored procedure, returning the name of the function or stored procedure.

9. A system for creating predefined query instructions $$PLSQL_UNIT based on the openGauss database, characterized in that: The system includes a creation server, and the creation server includes: The recognition module is used to identify predefined query instructions starting with $$ during the lexical parsing stage; The replacement module is used to identify predefined query instructions as expressions during the syntax processing phase and obtain corresponding content constants from compilation information and database metadata for replacement; Create a module to create a function corresponding to the predefined query instruction $$PLSQL_UNIT, and use this function to obtain compilation unit information.

10. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Database query instruction generation method and device, computer equipment and storage medium

    CN117909355A