Binding variable implementation method and device for interactive terminal of PostgreSQL database and medium
By using a syntax parser in the PostgreSQL database interactive terminal to generate syntax tree nodes and combining bind variable linked lists and hash tables to cache and manage variable resources, the problem of variables lacking data type attributes is solved, and effective reference and efficient execution of bind variables in PL/pgSQL are achieved.
Patent Information
- Application Number
- CN202510802800.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-16
- Publication Date
- 2025-09-26
AI Technical Summary
The variable mechanism in the PostgreSQL database interactive terminal lacks data type attributes and cannot be referenced as input/output parameters in anonymous blocks, functions, procedures, or complex SQL statements. This limits its application in PL/pgSQL programming and results in low execution efficiency.
The syntax parser parses bind variable operation statements to generate syntax tree nodes. The bind variable linked list and hash table cache manage variable resources. Combined with the extended query protocol, cross-layer data flow of bind variables is achieved, and direct reference to bind variables in PL/pgSQL is supported.
Bound variables have clear data type attributes, which improves execution efficiency, avoids database kernel communication, and enables effective reference of variables in complex SQL and PL/pgSQL, breaking through the limitations of traditional shell variables.
Smart Images

Figure CN120704684A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a method, device, and medium for implementing binding variables in a PostgreSQL database interactive terminal. Background Art
[0002] The PostgreSQL database is a relational database that supports complex queries, transactions, triggers, views, stored procedures, and other features, making it suitable for applications of all sizes. In the PostgreSQL database's interactive terminal (i.e., the PSQL client), variables are typically implemented using simple shell-style key-value pairs. This variable mechanism lacks data type attributes and cannot be referenced as input / output parameters in anonymous blocks, functions, procedures, or complex SQL. Furthermore, variables can only be used within the PSQL shell and cannot be referenced or used in data flows within SQL or PL / pgSQL. This significantly limits its application in PL / pgSQL programming, resulting in serious deficiencies in PSQL's procedural programming, parameter reuse, and execution efficiency. Summary of the Invention
[0003] To solve the above problems, this application proposes a method for implementing bind variables in a PostgreSQL database interactive terminal, which is applied to a PSQL client and includes:
[0004] Based on the client process, the bind variable operation statement is parsed by a syntax parser to generate a syntax tree node corresponding to the bind variable operation statement;
[0005] According to the syntax tree node, a corresponding variable operation is performed on the binding variable resource bound to the client process to obtain an updated binding variable resource; wherein the binding variable resource includes a binding variable linked list and a hash table cache corresponding to the binding variable;
[0006] Determining, by the syntax parser, whether the SQL statement to be executed references bind variables;
[0007] If yes, sending the SQL statement to the server through the extended query protocol, so that the server executes the SQL statement and returns the corresponding query result;
[0008] According to the query result, the variable value of the specified bind variable contained in the SQL statement in the bind variable linked list is updated, and the client process is exited.
[0009] In one implementation of the present application, the syntax parser includes a lexical analyzer and a syntax parser. The syntax parser parses the bind variable operation statement to generate a syntax tree node corresponding to the bind variable operation statement, specifically including:
[0010] Generate the C files corresponding to the lexical analyzer and grammatical analyzer through the lexical analyzer generator and grammatical analyzer generator;
[0011] The C file is called to split the bind variable operation statement into a plurality of tokens, and the plurality of tokens are combined into a grammar rule matching the bind variable operation statement to generate a grammar tree node corresponding to the grammar rule.
[0012] In one implementation of the present application, before sending the SQL statement to the server through the extended query protocol, the method further includes:
[0013] Call the C file corresponding to the grammar parser through the preset get_parameter interface to parse the SQL statement to determine the specified bind variables contained in the SQL statement and the variable names corresponding to the specified bind variables;
[0014] For each specified bind variable, a corresponding HostVarible object is constructed to implement an extended query of the SQL statement through the HostVarible object.
[0015] In one implementation of the present application, performing corresponding variable operations on the bound variable resources bound to the client process according to the syntax tree node to obtain updated bound variable resources specifically includes:
[0016] The syntax tree node includes at least one or more of the following: a variable name, an operation type, a data type, and an initial value of a bound variable;
[0017] According to the variable name, a target variable matching the variable name is searched from the bound variable resources bound by the client process to determine whether there is one, so as to specify a corresponding variable operation for the target variable according to the operation type, and obtain an updated bound variable resource.
[0018] In one implementation of the present application, searching, based on the variable name, from the bound variable resources bound to the client process to determine whether there is a target variable that matches the variable name specifically includes:
[0019] According to the variable name, searching a hash table cache bound to the client process to determine whether there is a target variable with the same name as the variable; wherein the access frequency of the variable stored in the hash table cache is greater than a preset value;
[0020] If not, search the bound variable list for a target variable that matches the variable name.
[0021] In one implementation of the present application, searching the bound variable list for a target variable that matches the variable name specifically includes:
[0022] For each variable in the bound variable list, compare the first character of the variable with the first character of the variable name to determine whether the two are consistent;
[0023] If so, call the memory comparison function to perform a byte comparison on the variable and the variable name, and determine that the variable is the target variable if the variable and the variable name are completely consistent.
[0024] In one implementation of the present application, after determining whether the two are consistent, the method further includes:
[0025] If not, it is determined that the variable does not match the variable name, and the variable is skipped to compare the first character of the next variable of the variable with the first character in the variable name.
[0026] In one implementation of the present application, after determining whether the SQL statement to be executed references a bind variable, the method further includes:
[0027] If not, the SQL statement is sent to the server through a simple query protocol, so that the server executes the SQL statement and returns a corresponding query result.
[0028] The present application embodiment provides a device for implementing binding variables of a PostgreSQL database interactive terminal, the device comprising:
[0029] at least one processor;
[0030] and, a memory communicatively coupled to the at least one processor;
[0031] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to:
[0032] Based on the client process, the bind variable operation statement is parsed by a syntax parser to generate a syntax tree node corresponding to the bind variable operation statement;
[0033] According to the syntax tree node, a corresponding variable operation is performed on the binding variable resource bound to the client process to obtain an updated binding variable resource; wherein the binding variable resource includes a binding variable linked list and a hash table cache corresponding to the binding variable;
[0034] Determining, by the syntax parser, whether the SQL statement to be executed references bind variables;
[0035] If yes, sending the SQL statement to the server through the extended query protocol, so that the server executes the SQL statement and returns the corresponding query result;
[0036] According to the query result, the variable value of the specified bind variable contained in the SQL statement in the bind variable linked list is updated, and the client process is exited.
[0037] An embodiment of the present application provides a non-volatile computer storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to:
[0038] Based on the client process, the bind variable operation statement is parsed by a syntax parser to generate a syntax tree node corresponding to the bind variable operation statement;
[0039] According to the syntax tree node, a corresponding variable operation is performed on the binding variable resource bound to the client process to obtain an updated binding variable resource; wherein the binding variable resource includes a binding variable linked list and a hash table cache corresponding to the binding variable;
[0040] Determining, by the syntax parser, whether the SQL statement to be executed references bind variables;
[0041] If yes, sending the SQL statement to the server through the extended query protocol, so that the server executes the SQL statement and returns the corresponding query result;
[0042] According to the query result, the variable value of the specified bind variable contained in the SQL statement in the bind variable linked list is updated, and the client process is exited.
[0043] The method for implementing bind variables in the interactive terminal of the PostgreSQL database proposed in this application can bring the following beneficial effects:
[0044] By generating syntax tree nodes through a parser, bind variables are assigned clear data type attributes. This addresses the fundamental flaw of the PSQL client, where shell variables lack data types and cannot participate in type validation. This paves the way for variable references in complex SQL and PL / pgSQL. Furthermore, bind variable operations are implemented client-side, avoiding communication with the database kernel and improving execution efficiency. Global management of bind variable resources, combined with the extended query protocol, enables direct reference of bind variables as input / output parameters in anonymous blocks, stored procedures, and dynamic SQL, enabling cross-layer data flow. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0046] Figure 1 A flowchart of a method for implementing bound variables in a PostgreSQL database interactive terminal provided in an embodiment of the present application;
[0047] Figure 2 A schematic diagram of the structure of a device for implementing binding variables for a PostgreSQL database interactive terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0049] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.
[0050] like Figure 1 As shown, an embodiment of the present application provides a method for implementing bound variables in a PostgreSQL database interactive terminal, which is applied to a PSQL client and includes:
[0051] S101: Based on the client process, a syntax parser is used to parse a bind variable operation statement to generate a syntax tree node corresponding to the bind variable operation statement.
[0052] The client integrates bind variables and the extended query protocol to address the issues of untyped variables in native PSQL clients and their inability to be used in PL / pgSQL programming. Bind variable operations are performed entirely in client memory, eliminating the need to connect to the database server. Bind variable creation, deletion, and modification are performed within the client process running locally on the PSQL client. The client process uses a parser to parse bind variable operation statements. By analyzing the syntax rules for creating, deleting, and manipulating bind variables, bind variables can be manipulated and maintained directly within the client process, eliminating the need to communicate with the database kernel and reducing communication overhead. However, if the parser identifies an SQL statement as an SQL statement rather than a bind variable operation, the SQL statement is sent to the database kernel for execution.
[0053] The syntax parser creates typed variables in memory, giving them database-level typing capabilities. The database kernel uses bind variable syntax to enable bind variables to be used directly in PL / pgSQL, breaking through the limitations of traditional shell variables. Furthermore, the extended query protocol can map variables to input / output parameters of extended queries, allowing them to be directly referenced in anonymous blocks, functions, procedures, or complex SQL.
[0054] In one embodiment, the structured processing of statements involving variable binding requires a parser. The parser is implemented using Bison (GNU Bison) and Flex (GNU Flex). Flex, as a lexical analyzer generator, generates C code corresponding to the lexical analyzer based on lexical rules, while Bison, as a grammatical analyzer generator, generates C code corresponding to the grammatical analyzer based on grammatical rules. Compiling the Bison and Flex files generates the C code file for the grammatical analyzer, and provides a parser interface for user invocation, thereby implementing string parsing.
[0055] Therefore, running the above C code can split the bind variable operation statement into several tokens through the cooperation of the lexical analyzer and the syntax analyzer, and then combine the split tokens into the grammar rules corresponding to the bind variable operation statement through the syntax analyzer, and then generate the syntax tree node corresponding to the grammar rule.
[0056] The syntax tree node returned by the parser includes at least one or more of the following: the name of the bound variable, the operation type, the data type, and the initial value. This basic information about the bound variables is stored in the client process's memory address space. This effectively avoids occupying database memory and immediately releases client resources when the client terminates the connection.
[0057] S102: performing corresponding variable operations on the binding variable resources bound to the client process according to the syntax tree nodes to obtain updated binding variable resources; wherein the binding variable resources include a binding variable linked list and a hash table cache corresponding to the binding variables.
[0058] Based on the parsed syntax tree nodes, the bound variable resources bound to the client process in local memory are managed. The bound variable storage structure includes a bound variable linked list and a hash table cache. Each node in the bound variable linked list corresponds to a bound variable, and the hash table cache stores frequently accessed bound variables. Using the variable name in the syntax tree node, the system searches for a matching target variable in the existing bound variable resources. Based on the operation type in the syntax tree node, the corresponding variable operation is performed on the bound variable resource, resulting in an updated bound variable resource.
[0059] To improve search efficiency when searching for a target variable, the hash table cache is first searched for a target variable with the same name as the variable. Since the access frequency of variables stored in the hash table cache is greater than a preset value, for these frequently accessed variables, if a direct hit is found in the hash table cache, there is no need to search the bound variable list, effectively improving the efficiency of binding variable resolution. If the target variable is not found in the hash table cache, the bound variable list is searched for a target variable that matches the variable name. A binary search can be used when searching the bound variable list, effectively improving binding variable search efficiency. If the target variable is not found in either the hash table cache or the bound variable list, an error message is generated. If the target variable is found, the internal structure of the target variable is returned, and maintenance operations are performed on it based on the operation type, updating the bound variable list and the hash table cache.
[0060] Among them, to search for the target variable in the bound variable list, it is necessary to compare the variable name with the variable name in the linked list node in turn. Its essence is to compare the character strings. This process needs to call the memory comparison function memcmp to implement. memcmp can compare whether the contents of two memory areas are completely consistent. Each time a linked list node is searched, memcmp needs to be called once. In order to save memory overhead, for each variable in the bound variable list, the embodiment of the present application adopts a first character comparison method to compare the first character of each variable in the bound variable list with the first character in the variable name to determine whether they are consistent. If they are consistent, it means that the first character of this variable is the same as the variable name, and there is a possibility of matching. At this time, it is necessary to continue calling the memory comparison function to continue comparing all bytes of the variable and the variable name. As long as the bytes of the variable and the variable name are completely consistent, it can be confirmed that the variable is the target variable that matches the variable name. If they are not consistent, then the two strings are definitely not equal. At this time, you can directly skip the memcmp call to this linked list node and directly check whether the first character of the next variable of the variable is consistent with the first character of the variable name. This effectively reduces the overhead of the memcmp function call.
[0061] S103: Determine, through a syntax parser, whether the SQL statement to be executed references a bind variable.
[0062] The above process describes the PSQL client's parsing of a bind variable operation statement. If the parser recognizes that the current statement is not a bind variable operation statement but a SQL statement to be executed, then based on the above extended use of the parser, the parser can determine whether the SQL statement references bind variables and then select the appropriate processing method to interact with the database server, execute and parse the SQL statement, and thus obtain the data query results.
[0063] The SQL statement can be SQL or PL / pgSQL. If bind variables are used in the SQL statement, the parser can detect the use of bind variables and reference the bind variables starting with a colon (for example, :variable). Native bind variables do not support this form starting with a colon. They all use $1 and $2 as bind parameter placeholders and cannot bind parameters by name. The bind variables in the embodiments of the present application are distinguished by name and support using names as binding media. Therefore, in the database kernel and in the Bison rule file, the grammatical rules for bind parameters are expanded to execute the recognition of named parameters and record the position information of each parameter.
[0064] In one embodiment, the present application implements a get_parameter interface that receives a SQL statement entered by the user and calls a C file corresponding to the parser through the interface. The parser then parses the SQL statement using the grammar rules in the C file to determine the specified bind variables and their corresponding variable names. Furthermore, for each identified bind variable, the extractor also needs to extract the corresponding bind parameter information, namely, the variable position, data type, and IN / OUT attributes.
[0065] The get_parameter interface returns a parameter list containing all identified bind variables. Based on this parameter list, the PSQL client constructs a corresponding HostVarible object for each bind variable. Specifically, based on the bind variable name, the client searches the bind variable list and hash table cache to see if the bind variable has been defined. If it can be found, the client retrieves the current value of the bind variable. Next, based on the parameter list and variable value, the client constructs a HostVarible object, which can be used for extended queries in subsequent SQL statements.
[0066] S104: If yes, send the SQL statement to the server through the extended query protocol, so that the server executes the SQL statement and returns the corresponding query result.
[0067] If a SQL statement references bind variables, it is necessary to send the SQL statement to the server using the extended query protocol. Otherwise, for a SQL statement that does not reference bind variables, it is sent directly to the server using the simple query protocol to obtain the corresponding query results. The character Q in the message packet of the simple query protocol indicates that this data packet is the simple query protocol.
[0068] The extended query protocol is a protocol for communication between the client and the server, which allows the client to send more complex query requests. Unlike the simple query protocol, the extended query protocol supports prepared statements (Prepare), bound parameters (Bind) and execution steps (Execute), thereby improving performance and flexibility. The embodiment of the present application implements a set of PBE interfaces based on the native extended query protocol. This interface does not frequently apply for the release of statement handles, better reuses the resources of bound variables, and supports the legality and security checks of various dimensions of bound variables. The server receives SQL statements containing bound variables through the extended query protocol, and combines it with the pre-generated syntax tree structure to enable the server to cache parameterized execution plans. The same SQL template only needs to be hard parsed for the first time, and can be executed by subsequently replacing the bound variable values, reducing the CPU load on the database side.
[0069] Specifically, the extended query protocol is processed in three phases and messages, each consisting of three message packets: the P protocol, the B protocol, and the E protocol. The P protocol parses, analyzes, and plans SQL statements, saving time on subsequent executions of the same SQL statement. The B protocol saves the statistical plan in a named portal, which serves as input for the E protocol. The detailed process is as follows:
[0070] P protocol: Parses, analyzes, and plans SQL statements, reducing the overhead of SQL rules.
[0071] Protocol B: Generates a named portal and caches the execution plan.
[0072] E protocol: Execute portal.
[0073] The above process executes the SQL statement that references the bind variable using the extended query protocol (PBE), and uses the bind variable as the bind value of the extended query.
[0074] S105: updating the variable value of the specified bind variable contained in the SQL statement in the bind variable linked list according to the query result, and exiting the client process.
[0075] After receiving the query result from the server, you need to feed it back to the specified bind variable. This means updating the variable value corresponding to the specified bind variable in the SQL statement in the bind variable list. After completing the update of the specified bind variable, the PSQL client process automatically exits, releasing the resources of the specified bind variable.
[0076] The above are embodiments of the method proposed in this application. Based on the same idea, some embodiments of this application also provide devices and non-volatile computer storage media corresponding to the above methods.
[0077] Figure 2 This is a schematic diagram of the structure of the binding variable implementation device of the PostgreSQL database interactive terminal provided in the embodiment of the present application. Figure 2 Shown, including:
[0078] at least one processor; and,
[0079] at least one processor communicatively connected to a memory; wherein,
[0080] The memory stores instructions that can be executed by at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to execute the binding variable implementation method of the PostgreSQL database interactive terminal as described in any one of the above items.
[0081] The embodiment of the present application provides a non-volatile computer storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured as follows:
[0082] The method for implementing bind variables in the interactive terminal of a PostgreSQL database as described in any one of the above items.
[0083] The various embodiments in this application are described in a progressive manner. Similar portions between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the device and 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.
[0084] The devices and media provided in the embodiments of the present application correspond one-to-one to the methods. Therefore, the devices and media also have similar beneficial technical effects to their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.
[0085] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt 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.) that contain computer-usable program code.
[0086] The present application 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 the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 steps in the process. 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.
[0087] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0088] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0089] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0090] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0091] 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 tape, 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.
[0092] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0093] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A method for implementing bind variables in an interactive terminal of a PostgreSQL database, characterized in that: Applied to a PSQL client, the method includes: Based on the client process, the bind variable operation statement is parsed by a syntax parser to generate a syntax tree node corresponding to the bind variable operation statement; According to the syntax tree node, a corresponding variable operation is performed on the binding variable resource bound to the client process to obtain an updated binding variable resource; wherein the binding variable resource includes a binding variable linked list and a hash table cache corresponding to the binding variable; Determining, by the syntax parser, whether the SQL statement to be executed references bind variables; If yes, sending the SQL statement to the server through the extended query protocol, so that the server executes the SQL statement and returns the corresponding query result; According to the query result, the variable value of the specified bind variable contained in the SQL statement in the bind variable linked list is updated, and the client process is exited.
2. The method for implementing bound variables of a PostgreSQL database interactive terminal according to claim 1, wherein: The syntax parser includes a lexical analyzer and a syntax parser. The syntax parser parses the bind variable operation statement to generate a syntax tree node corresponding to the bind variable operation statement, specifically including: Generate the C files corresponding to the lexical analyzer and grammatical analyzer through the lexical analyzer generator and grammatical analyzer generator; The C file is called to split the bind variable operation statement into a plurality of tokens, and the plurality of tokens are combined into a grammar rule matching the bind variable operation statement to generate a grammar tree node corresponding to the grammar rule.
3. The method for implementing bound variables of a PostgreSQL database interactive terminal according to claim 1, wherein: Before sending the SQL statement to the server through the extended query protocol, the method further includes: Call the C file corresponding to the grammar parser through the preset get_parameter interface to parse the SQL statement to determine the specified bind variables contained in the SQL statement and the variable names corresponding to the specified bind variables; For each specified bind variable, a corresponding HostVarible object is constructed to implement an extended query of the SQL statement through the HostVarible object.
4. The method for implementing bound variables of a PostgreSQL database interactive terminal according to claim 1, wherein: According to the syntax tree node, performing corresponding variable operations on the bound variable resources bound to the client process to obtain updated bound variable resources specifically includes: The syntax tree node includes at least one or more of the following: a variable name, an operation type, a data type, and an initial value of a bound variable; According to the variable name, a target variable matching the variable name is searched from the bound variable resources bound by the client process to determine whether there is one, so as to specify a corresponding variable operation for the target variable according to the operation type, and obtain an updated bound variable resource.
5. The method for implementing bound variables of a PostgreSQL database interactive terminal according to claim 4, wherein: According to the variable name, searching the bound variable resources bound to the client process for a target variable that matches the variable name includes: According to the variable name, searching a hash table cache bound to the client process to determine whether there is a target variable with the same name as the variable; wherein the access frequency of the variable stored in the hash table cache is greater than a preset value; If not, search the bound variable list for a target variable that matches the variable name.
6. The method for implementing bound variables of a PostgreSQL database interactive terminal according to claim 5, wherein: Searching the bound variable list for a target variable that matches the variable name specifically includes: For each variable in the bound variable list, compare the first character of the variable with the first character of the variable name to determine whether the two are consistent; If so, call the memory comparison function to perform a byte comparison on the variable and the variable name, and determine that the variable is the target variable if the variable and the variable name are completely consistent.
7. The method for implementing bound variables of a PostgreSQL database interactive terminal according to claim 6, wherein: After determining whether the two are consistent, the method further includes: If not, it is determined that the variable does not match the variable name, and the variable is skipped to compare the first character of the next variable of the variable with the first character in the variable name.
8. The method for implementing bound variables of a PostgreSQL database interactive terminal according to claim 1, wherein: After determining whether the SQL statement to be executed references a bind variable, the method further includes: If not, the SQL statement is sent to the server through a simple query protocol, so that the server executes the SQL statement and returns a corresponding query result.
9. A bind variable implementation device for a PostgreSQL database interactive terminal, characterized in that: The device comprises: at least one processor; and, a memory communicatively coupled to the at least one processor; The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the binding variable implementation method of the PostgreSQL database interactive terminal according to any one of claims 1 to 8.
10. A non-volatile computer storage medium storing computer executable instructions, characterized in that: The computer executable instructions are configured to: A method for implementing bind variables in a PostgreSQL database interactive terminal according to any one of claims 1 to 8.