A package function implementation method, system and medium based on PostgreSQL database
By using recursive compilation and HASH table management package objects in PostgreSQL database, the problems of chaotic Schema namespace and high resource consumption are solved, and unified management and efficient access of package objects are achieved.
Patent Information
- Application Number
- CN202510856639.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-25
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2045-06-25
AI Technical Summary
The PostgreSQL database community version does not support the Package mechanism, resulting in confusing Schema namespace, high resource consumption and difficulty in managing decentralized storage package objects.
Recursive compilation technology is used to store package objects in a HASH table in local memory, and package definition is managed through a system table to avoid decentralized storage and improve access efficiency.
It reduces the invasion of system OID resources, improves packet access efficiency, solves the problems of chaotic Schema namespace and excessive resource consumption, and realizes unified management of package objects.
Smart Images

Figure CN120353823B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a method, system, and medium for implementing package functions based on a PostgreSQL database. Background Art
[0002] In the database field, packages, as object-oriented encapsulation units, can integrate objects such as types, variables, and procedures and support public / private access control. They are widely used in enterprise-level applications.
[0003] However, the PostgreSQL database community version does not support the Package mechanism. Therefore, existing technologies usually simulate Package based on the schema of the same name or implement package functions by adding new system tables.
[0004] Because PostgreSQL uses schemas as namespace containers, this method, which creates schemas with the same name to store package objects, can easily lead to chain reactions. For example, as the number of packages increases, schema explosion leads to namespace confusion and is incompatible with scenarios where packages with the same name exist in multiple schemas. Package objects are stored in multiple system tables, requiring individual updates or deletions, triggering cascading modifications across multiple tables, resulting in poor performance and consuming system OID resources. Adding new system tables uniformly stores package definitions, but functions and types within the package are still stored in native system tables. Global variables require separate tables, resulting in fragmented data and difficult cross-table management. Deletions require simultaneous updates to multiple tables, making it difficult to ensure transactional consistency. Furthermore, when types within a package are stored in the type table, schema naming conflicts may occur, making it impossible to distinguish between the package name and the schema name.
[0005] Therefore, since Package is frequently used in actual applications, the method of relying on Schema or native system tables to implement package functions not only consumes too much system resources, but also makes it difficult to effectively manage dispersed packages. Summary of the Invention
[0006] The embodiments of the present application provide a package function implementation method, system, and medium based on a PostgreSQL database, which are used to solve the following technical problems: Since Package is frequently used in actual applications, the method of relying on Schema or native system tables to implement package functions not only consumes too much system resources, but also makes it difficult to effectively manage dispersed stored packages.
[0007] The embodiments of this application adopt the following technical solutions:
[0008] The present invention provides a package function implementation method based on a PostgreSQL database. The method comprises: parsing a DDL statement submitted by a user to obtain package processing information; wherein the package processing information includes the package name, the schema to which it belongs, and the definition text; processing the original definition of the package to be processed in a system table based on the package processing information; converting the processed original definition into a package instantiation object through recursive compilation based on the object dependency relationship corresponding to the package to be processed, and storing the package instantiation object in a hash table in local memory; responding to a package object access instruction, obtaining the package name and object name, and querying and accessing the required object in the hash table based on the package name and object name.
[0009] The embodiment of the present application stores the original definition of the Package in only one new system table, thus avoiding the scattered storage of package objects in multiple system tables and achieving unified management of package definitions. Recursive compilation is used to store the objects instantiated by the package in a HASH table in memory, and corresponding interfaces are added to access the objects in the HASH table. All objects in the package can be accessed by directly referencing the memory objects in the HASH table. Therefore, the objects in the package of the embodiment of the present application do not enter the system table. After being referenced, they occupy local memory, thereby reducing the occupation of system OID (Object Identifier) resources. In addition, the embodiment of the present application accelerates package access and improves package access efficiency through HASH storage.
[0010] In one implementation of the present application, based on the package processing information, the original definition of the package to be processed is processed accordingly in the system table, specifically including: when the package processing information corresponds to package creation, the definition text corresponding to the package to be processed obtained after parsing is stored in the system table; the syntax corresponding to the package to be processed is detected; if there is a syntax error, it is prompted that the definition text storage failed and the creation operation is rolled back; if there is no syntax error, it is determined that the definition text storage is successful, and the original definition corresponding to the package to be processed is obtained.
[0011] In one implementation of the present application, after the DDL statement submitted by the user is parsed and the package processing information is obtained, the method also includes: when the package processing information corresponds to a package modification, determining the original definition corresponding to the package to be processed in the system table, and replacing the new definition text corresponding to the package to be processed to the original definition position corresponding to the package to be processed; recursively compiling the replaced original definition to obtain a new package instantiation object; replacing the new package instantiation object to the original package instantiation object position corresponding to the package to be processed in the HASH table; performing syntax checking on the updated content, and reporting an error if there is a syntax error; when there are other sessions that depend on the package to be processed for conversation, starting the lazy update strategy, and after the session ends, performing a package modification operation on the package to be processed.
[0012] In one implementation of the present application, after the DDL statement submitted by the user is parsed and the package processing information is obtained, the method also includes: when the package processing information corresponds to a package deletion, determining the original definition corresponding to the package to be processed in the system table, and determining the package instantiation object corresponding to the package to be processed in the HASH table; deleting the original definition and the package instantiation object; and deleting the dependency relationship corresponding to the package to be processed.
[0013] In one implementation of the present application, based on the object dependency relationship corresponding to the package to be processed, the processed original definition corresponding to the package to be processed is converted into a package instantiation object through recursive compilation, specifically including: when an external program references a package object and the package object is not in the HASH table, triggering recursive compilation; reading the original definition corresponding to the package to be processed in the system table, and parsing the original definition into an abstract syntax tree; traversing the abstract syntax tree to determine the object dependency relationship corresponding to the package to be processed; putting the current compilation environment into the global stack, and reading the string of the referenced package in the system table based on the object dependency relationship, parsing and compiling to obtain the dependent object; based on the type, function and variable corresponding to the dependent object, constructing an instantiation object and storing it in the HASH table of the local memory.
[0014] In one implementation of the present application, after converting the processed original definition corresponding to the package to be processed into a package instantiation object through recursive compilation, the method also includes: isolating private objects from public objects through namespaces; when accessing externally, querying in the public namespace; when accessing internally, first querying in the private namespace, and then querying from the public namespace.
[0015] In one implementation of the present application, based on the package name and the object name, the required object query access is performed in the HASH table, specifically including: determining the unique identifier of the package according to the package name; using the unique identifier of the package as the index key, querying in the HASH table to determine the required instantiation; using the object name as the index key, performing a secondary query in the required instantiation to determine the required object.
[0016] In one implementation of the present application, each package in the HASH table corresponds to a memory context; when the package is compiled, a memory context is generated and the memory context is bound to the life cycle of the package; when the package is deleted, the memory context is released; when the package is recompiled, a new memory context is regenerated and the memory context before compilation is deleted.
[0017] An embodiment of the present application provides a package function implementation system based on a PostgreSQL database, including: a DDL operation module, which is used to perform syntax parsing on DDL statements submitted by users to obtain package processing information; wherein the package processing information includes the package name, the schema to which it belongs, and the definition text; an original definition table module, which, based on the package processing information, performs corresponding processing on the original definition of the package to be processed in the system table; a recursive compilation module, which, based on the object dependency corresponding to the package to be processed, converts the processed original definition into a package instantiation object through recursive compilation; a HASH storage module, which is used to store the package instantiation object in a HASH table in local memory; an object search module, which is used to respond to package object access instructions, obtain the package name and object name, and perform query access to the required object in the HASH table based on the package name and object name.
[0018] A non-volatile computer storage medium provided by an embodiment of the present application stores computer-executable instructions, wherein the computer-executable instructions are configured to: parse a DDL statement submitted by a user to obtain package processing information; wherein the package processing information includes a package name, a corresponding schema, and a definition text; based on the package processing information, perform corresponding processing on the original definition of the package to be processed in a system table; based on the object dependency relationship corresponding to the package to be processed, convert the processed original definition into a package instantiation object through recursive compilation, and store the package instantiation object in a hash table in local memory; respond to a package object access instruction, obtain the package name and object name, and perform query access to the required object in the hash table based on the package name and object name.
[0019] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects: the embodiments of the present application store the original definition of the Package in only one new system table, thereby avoiding the scattered storage of package objects in multiple system tables and realizing unified management of package definitions. Recursive compilation is adopted to store the objects instantiated by the package in the HASH table of the memory, and the corresponding interface is added to access the objects in the HASH table. All access objects in the package can directly reference the memory objects in the HASH table. Therefore, the objects in the package of the embodiments of the present application do not enter the system table. After being referenced, they occupy local memory, thereby reducing the encroachment on system OID resources. In addition, the embodiments of the present application accelerate the access to the package and improve the efficiency of package access through HASH storage. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments described in the present application. For those skilled in the art, other drawings can be obtained based on these drawings without inventive work. In the drawings:
[0021] Figure 1 A flowchart of a package function implementation method based on a PostgreSQL database provided in an embodiment of the present application;
[0022] Figure 2 A schematic diagram of a package function implementation system based on a PostgreSQL database provided in an embodiment of the present application.
[0023] Reference numerals:
[0024] 200: Package function implementation system based on PostgreSQL database, 201: DDL operation module, 202: Original definition table module, 203: Recursive compilation module, 204: HASH storage module, 205: Object search module. DETAILED DESCRIPTION
[0025] Embodiments of the present application provide a method, system, and medium for implementing package functions based on a PostgreSQL database.
[0026] In order to enable those skilled in the art to better understand the technical solutions in this application, the following will clearly and completely describe the technical solutions in the embodiments of this application in conjunction with the drawings in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0027] The technical solutions proposed in the embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0028] Figure 1 A flowchart of a package function implementation method based on a PostgreSQL database provided in an embodiment of the present application is shown as follows: Figure 1 As shown, the package function implementation method based on the PostgreSQL database includes the following steps:
[0029] Step 101: Parse the DDL statement submitted by the user to obtain package processing information.
[0030] In one implementation of the present application, when a user executes a DDL statement such as CREATE PACKAGE, CREATE PACKAGEBODY, ALTER PACKAGE, or DROP PACKAGE, the DDL statement submitted by the user is parsed to obtain package processing information. Based on the package processing information, it is determined whether the package is created, modified, or deleted, as well as the package name, schema, and definition content (such as types, variables, procedures, etc.).
[0031] Step 102: Based on the packet processing information, the original definition of the packet to be processed is processed in the system table.
[0032] In one implementation of the present application, when the package processing information corresponds to package creation, the definition text corresponding to the pending package obtained after parsing is stored in a system table. The syntax of the pending package is checked. If a syntax error is found, a notification indicating that the definition text storage failed is displayed, and the creation operation is rolled back. If no syntax error is found, the definition text is determined to have been successfully stored, and the original definition corresponding to the pending package is obtained.
[0033] Specifically, when CREATE PACKAGE or CREATE PACKAGE BODY corresponds to a package creation statement, the parsed definition text of the Package is stored in a newly added system table. The embodiment of the present application does not create any other database objects.
[0034] Furthermore, during creation, a syntax check is performed on the package. If there is a syntax error, the creation fails and the creation operation is rolled back.
[0035] Step 103: Based on the object dependency relationship corresponding to the package to be processed, the processed original definition is converted into a package instantiation object through recursive compilation, and the package instantiation object is stored in a HASH table in the local memory.
[0036] In one implementation of the present application, when an external program references a package object and the package object is not in the HASH table, recursive compilation is triggered. The original definition corresponding to the package to be processed is read from the system table and parsed into an abstract syntax tree. The abstract syntax tree is traversed to determine the object dependency relationship corresponding to the package to be processed. The current compilation environment is put into the global stack, and based on the object dependency relationship, the string of the referenced package is read from the system table and parsed and compiled to obtain the dependent object. Based on the type, function, and variable corresponding to the dependent object, an instantiated object is constructed and stored in the HASH table in the local memory.
[0037] Specifically, when the package processing information corresponds to package creation, if an external program references a package object that is not in the hash table, the recursive compilation module is triggered. The current compilation environment must be saved before the package is compiled. All objects declared in the package (variables, functions, types, etc.) are syntax-checked and semantically analyzed to generate an intermediate representation (IR).
[0038] If the compilation is successful, the metadata of the package is registered in the memory HASH table; if the compilation fails, the package status invalid error is reported, and after the compilation of this package is completed, the current compilation environment is restored.
[0039] Furthermore, the package definition is converted into an executable memory object by recursively compiling the module. The specific steps are as follows:
[0040] Parsing entry: Read the original SQL definition from the system table and parse it into an abstract syntax tree.
[0041] Dependency analysis: Traverse the abstract syntax tree in declaration order and identify object dependencies, such as package A references package B.
[0042] Compilation environment preservation: If there is a dependency, the current compilation environment is pushed into the global stack, and then the string of the referenced package is read from the system table for parsing.
[0043] Recursive instantiation: After compiling the dependent objects, instantiated objects are constructed based on their types, functions, and variables and stored in a local HASH table for use when users reference the objects.
[0044] Permission isolation: Use namespaces to isolate private objects from public objects. When accessed from the outside, the public namespace is searched. When accessed from the inside, the private namespace is searched first, and then the public objects are searched. This embodiment of the application implements a two-level namespace search. When accessed from the outside, only the public namespace is searched, ensuring that private objects are completely invisible. When accessed from the inside, the private namespace is searched first, implementing a private-first encapsulation logic.
[0045] Error handling: If an object fails to compile, the package status is set to invalid. Subsequent access to the package will display the invalid status.
[0046] Restore the current compilation environment: Pop the current compilation environment from the global stack and continue compiling.
[0047] The embodiment of the present application saves the compilation environment through a global stack, recursively instantiates when processing cross-package dependencies, ensures that all objects in the dependency chain are correctly compiled, generates an intermediate representation during the compilation phase, converts the SQL text into an efficient memory structure, reduces repeated parsing overhead, and improves execution efficiency. Secondly, the embodiment of the present application stores the compiled objects in an in-memory HASH table to improve query efficiency. Compared with the traditional method of traversing the system table, the performance is significantly improved. In addition, the embodiment of the present application supports multi-level dependencies, maintains the compilation context through a stack mechanism, and ensures the correct parsing of complex dependency chains.
[0048] In one implementation of the present application, when the package processing information corresponds to a package modification, the original definition corresponding to the package to be processed is determined in the system table, and the new definition text corresponding to the package to be processed is replaced to the original definition position corresponding to the package to be processed. The replaced original definition is recursively compiled again to obtain a new package instantiation object. In the HASH table, the new package instantiation object is replaced to the original package instantiation object position corresponding to the package to be processed. The updated content is syntax-checked, and an error message is given if there is a syntax error. If there are other sessions that depend on the package to be processed for conversation, the lazy update strategy is started, and after the session ends, the package modification operation is performed on the package to be processed.
[0049] Specifically, when the DDL statement sent by the user is ALTER PACKAGE, the corresponding original definition in the system table is updated.
[0050] Specifically, the entire Package is recompiled through the recursive compilation module, the old content in the HASH table is deleted, and the compiled new content is stored in the HASH table. If there is a syntax error, an error is reported.
[0051] Furthermore, if other sessions have sessions or transactions that depend on the Package, the lazy update strategy is activated and takes effect after the session ends. The embodiment of the present application maintains the metadata and status of the package through a HASH table, supports the lazy update strategy, and ensures stability during runtime.
[0052] In one implementation of the present application, when the packet processing information corresponds to a package deletion, the original definition corresponding to the package to be processed is determined in the system table, and the package instantiation object corresponding to the package to be processed is determined in the hash table. The original definition and the package instantiation object are deleted, and the dependency relationship corresponding to the package to be processed is deleted.
[0053] Specifically, when the DDL statement sent by the user is DROP PACKAGE, the record is deleted from the system table, all related objects in the memory HASH table are released, and the dependencies between related objects are cleared.
[0054] In the embodiment of the present application, since the object is only stored in memory, there is no need to operate other system tables (such as pg_proc, pg_type), avoiding OID resource occupation and system table expansion.
[0055] Step 104: Respond to the package object access instruction, obtain the package name and object name, and perform query access on the required object in the HASH table based on the package name and object name.
[0056] In one implementation of the present application, the key points of the HASH table design in the embodiment of the present application include the following two parts:
[0057] (1) Two-level structure:
[0058] The first level uses the package's unique identifier as the key, pointing to the instantiation object of the package.
[0059] The second level uses the object name in the package as the key to store object instances, such as function pointers and variable values.
[0060] (2) Memory management:
[0061] The HASH table is in a new global memory context, which is at the session level.
[0062] When compiling a package, a memory context is generated and bound to the package lifecycle. When deleting the package, the memory context is released. When recompiling the package, a new memory context is generated and the previous memory context is deleted.
[0063] In one implementation of the present application, a unique identifier for the package is determined based on the package name, and the unique identifier is used as an index key to query a HASH table to determine the desired instantiation. A second query is performed in the desired instantiation using the object name as the index key to determine the desired object.
[0064] Specifically, when a user accesses an object in a Package, the search process is as follows:
[0065] Parse the name: Decompose the package object information sent by the user into two parts: package name and object name, and determine the unique identifier of the package based on the package name.
[0066] HASH table query: Use the unique identifier of the package as the index key to search the in-memory HASH table. After finding the instantiation of the package, retrieve specific attributes such as type, variables, functions, etc. based on the object name.
[0067] If the package name does not exist, the original system object is searched. If the package object name does not exist in the original system object, an error is reported.
[0068] Permission verification: For access within a package, the search starts from the private namespace; for access outside the package, the search starts from the public namespace.
[0069] Cache acceleration: Frequently accessed objects retain copies in the session-level cache to reduce HASH table lock contention.
[0070] In the embodiment of the present application, objects within the package are not written to the system table, thus avoiding the problem of OID resource exhaustion. Secondly, the memory HASH table is faster to access than the disk system table, and recursive compilation and on-demand loading reduce startup overhead. In the embodiment of the present application, package definitions are uniformly managed through the pg_package table, and there is no need to traverse multiple system tables when deleting. In addition, the embodiment of the present application supports the coexistence of package names and schema names, avoiding the same-name conflicts of traditional Schema solutions, enhancing compatibility, and isolating private objects and improving security through compile-time permission tags and runtime verification.
[0071] Figure 2 A schematic diagram of a package function implementation system based on a PostgreSQL database is provided in the embodiment of the present application. Figure 2 As shown, a package function implementation system 200 based on a PostgreSQL database includes: a DDL operation module 201, an original definition table module 202, a recursive compilation module 203, a HASH storage module 204, and an object search module 205. The DDL operation module 201 is used to parse the DDL statements submitted by the user to obtain package processing information; the package processing information includes the package name, the schema to which it belongs, and the definition text; the original definition table module 202, based on the package processing information, processes the original definition of the package to be processed in the system table accordingly; the recursive compilation module 203, based on the object dependencies corresponding to the package to be processed, converts the processed original definition into a package instantiation object through recursive compilation; the HASH storage module 204 is used to store the package instantiation object in a HASH table in local memory; and the object search module 205 is used to respond to package object access instructions, obtain the package name and object name, and query and access the required object in the HASH table based on the package name and object name.
[0072] A non-volatile computer storage medium provided by an embodiment of the present application stores computer-executable instructions, wherein the computer-executable instructions are configured to: parse a DDL statement submitted by a user to obtain package processing information; wherein the package processing information includes a package name, a corresponding schema, and a definition text; based on the package processing information, perform corresponding processing on the original definition of the package to be processed in a system table; based on the object dependency relationship corresponding to the package to be processed, convert the processed original definition into a package instantiation object through recursive compilation, and store the package instantiation object in a hash table in local memory; respond to a package object access instruction, obtain the package name and object name, and perform query access to the required object in the hash table based on the package name and object name.
[0073] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Thus, the embodiments of this specification may take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware. Furthermore, the embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0074] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0075] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0076] The various embodiments in this application are described in a progressive manner. Similar portions between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from the other embodiments. In particular, the device, apparatus, and non-volatile computer storage medium embodiments are generally similar to the method embodiments, so their descriptions are relatively simple. For relevant portions, refer to the descriptions of the method embodiments.
[0077] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. It will be apparent to those skilled in the art that various modifications and variations may be made to the embodiments of the present application. However, such modifications or substitutions do not deviate from the spirit and scope of the technical solutions of the various embodiments of the present application.
Claims
1. A package function implementation method based on PostgreSQL database, characterized in that: The method comprises: Parse the DDL statement submitted by the user to obtain package processing information; wherein the package processing information includes the package name, the schema to which it belongs, and the definition text; Based on the packet processing information, the original definition of the packet to be processed is processed accordingly in the system table; Based on the object dependency relationship corresponding to the package to be processed, convert the processed original definition into a package instantiation object through recursive compilation, and store the package instantiation object in a HASH table in the local memory; Responding to the package object access instruction, obtaining the package name and the object name, and performing a query and access to the required object in the HASH table based on the package name and the object name; Based on the packet processing information, the original definition of the packet to be processed is processed in the system table, specifically including: In a case where the packet processing information corresponds to a packet creation, storing the definition text corresponding to the packet to be processed obtained after parsing into the system table; Detecting the syntax corresponding to the packet to be processed; If there is a syntax error, it will prompt that the definition text storage fails and roll back the creation operation; If there is no grammatical error, determining that the definition text is stored successfully, and obtaining the original definition corresponding to the package to be processed; The step of converting the processed original definition corresponding to the package to be processed into a package instantiation object by recursive compilation based on the object dependency relationship corresponding to the package to be processed specifically includes: When an external program references a package object and the package object is not in the HASH table, recursive compilation is triggered; Reading the original definition corresponding to the to-be-processed package in the system table, and parsing the original definition into an abstract syntax tree; Traversing the abstract syntax tree to determine the object dependency relationship corresponding to the package to be processed; The current compilation environment is put into the global stack, and based on the object dependency, the string of the reference package is read from the system table, and parsed and compiled to obtain the dependent object; Based on the type, function and variable corresponding to the dependent object, an instantiated object is constructed and stored in a HASH table in the local memory.
2. A package function implementation method based on PostgreSQL database according to claim 1, characterized in that, After parsing the DDL statement submitted by the user to obtain the package processing information, the method further includes: In a case where the packet processing information corresponds to a packet modification, determining the original definition corresponding to the to-be-processed packet in the system table, and replacing the new definition text corresponding to the to-be-processed packet to the original definition position corresponding to the to-be-processed packet; Recursively compile the replaced original definition to obtain a new package instantiation object; In the HASH table, the new packet instantiation object is replaced to the original packet instantiation object position corresponding to the packet to be processed; Perform grammar check on the updated content and report errors if there are any grammatical errors; When there are other sessions that rely on the package to be processed for conversation, the lazy update strategy is started, and after the session ends, the package modification operation is performed on the package to be processed.
3. A package function implementation method based on PostgreSQL database according to claim 1, characterized in that, After parsing the DDL statement submitted by the user to obtain the package processing information, the method further includes: In a case where the packet processing information corresponds to a packet deletion, determining the original definition corresponding to the packet to be processed in the system table, and determining the package instantiation object corresponding to the packet to be processed in the HASH table; Deleting the original definition and the package instantiation object; And, the dependency relationship corresponding to the package to be processed is deleted.
4. A package function implementation method based on PostgreSQL database according to claim 1, characterized in that, After converting the processed original definition corresponding to the to-be-processed package into a package instantiation object through recursive compilation, the method further includes: Isolate private objects from public objects through namespaces; When accessing externally, queries are performed in the public namespace; When accessing internally, the query is first performed in the private namespace, and then the query is performed from the public namespace.
5. A package function implementation method based on PostgreSQL database according to claim 1, characterized in that, The query access of the required object in the HASH table based on the package name and the object name specifically includes: Determine a unique identifier for the package based on the package name; Using the unique identifier of the package as an index key, querying the HASH table to determine the required instantiation; Using the object name as an index key, a secondary query is performed in the desired instantiation to determine the desired object.
6. A package function implementation method based on PostgreSQL database according to claim 1, characterized in that, Each package in the HASH table corresponds to a memory context; When compiling a package, the memory context is generated and bound to the life cycle of the package; When deleting a package, the memory context is released; When recompiling the package, a new memory context is regenerated and the memory context before compilation is deleted.
7. A package function implementation system based on a PostgreSQL database, applied to the method according to any one of claims 1 to 6, characterized in that: The system comprises: The DDL operation module is used to parse the DDL statements submitted by the user to obtain package processing information; wherein the package processing information includes the package name, the schema to which it belongs, and the definition text; An original definition table module processes the original definition of the to-be-processed packet in the system table based on the packet processing information; A recursive compilation module, based on the object dependency relationship corresponding to the package to be processed, converts the processed original definition into a package instantiation object through recursive compilation; A HASH storage module, used to store the package instantiation object in a HASH table in local memory; The object search module is used to respond to the package object access instruction, obtain the package name and the object name, and perform a query and access on the required object in the HASH table based on the package name and the object name.
8. A non-volatile computer storage medium storing computer-executable instructions, characterized in that: The computer executable instructions can execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Data interaction method and interaction device based on postgreSQL client PSQL
CN112965995A
Cross-platform dependency packet management method, system and device and storage medium
CN118963822A