Storage method for temporary large object in database and related product
By generating temporary large object registration tables and storage tables in the database, the life cycle of temporary large objects is managed, and the problems of waste of temporary large objects storage resources and inconsistent life cycles are solved, and database performance is improved.
Patent Information
- Application Number
- CN202411046752.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-11-01
AI Technical Summary
In the database, the storage of temporary large objects leads to wasted storage resources, and their life cycle is inconsistent with the session, affecting database performance.
By determining the target session, a temporary large object registration table and storage table are generated, reference information and data of the temporary storage target are recorded, and the life cycle of the temporary storage target is managed according to the session life cycle, ensuring that the temporary large object is deleted at the end of the session.
It realizes separate storage and life cycle management of temporary large objects, avoids waste of storage resources and improves database performance.
Smart Images

Figure CN118885485A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular to a storage method for temporary large objects in a database and related products. Background Art
[0002] Large Object is a special type of data in the database, mainly including Binary Large Object (BLOB) and Character Large Object / National Character Large Object (CLOB / NCLOB). BLOB is used to store binary large object data, such as images, audio files, videos or other non-text format data; CLOB and NCLOB are used to store large amounts of character data, suitable for storing long texts such as articles, reports or XML documents. The upper limit of the volume of a single data item of this type of data is very high, up to GB or even TB, and the volume varies greatly. The small amount of data can be as small as a few bytes or even empty.
[0003] During the operation of the database, it is sometimes necessary to create some temporary large objects. They do not belong to any user business table (base table). Therefore, after the Session is started, such temporary large objects need to be stored separately to avoid temporary large objects still being stored in the database after the Session ends, wasting database storage space and other resources. Summary of the invention
[0004] In view of the above problems, the present invention proposes a storage method for temporary large objects in a database and related products that overcome the above problems or at least partially solve the above problems.
[0005] It is an object of the present invention to store temporary large objects separately.
[0006] A further object of the present invention is to ensure that the life cycle of a temporary large object is consistent with the session.
[0007] In particular, the present invention provides a method for storing temporary large objects in a database, comprising:
[0008] Identify the target session in the database;
[0009] Get the temporary large object to be stored in the target session as the temporary storage target;
[0010] Generate a temporary large object registration table according to the target session, the temporary large object registration table is used to record reference information of the temporary storage target;
[0011] A temporary large object storage table is established, which is used to record data of temporary storage targets and corresponds to the temporary large object registration table.
[0012] Optionally, after the step of establishing a temporary large object storage table, the following steps are further included:
[0013] Set a life cycle for the temporary storage target. The life cycle of the temporary storage target is determined by the life cycle of the variable bound to the temporary storage target.
[0014] When the lifecycle is reached, the temporary storage target is deleted.
[0015] Optionally, after the step of establishing a temporary large object storage table, the following steps are further included:
[0016] At the end of the target session, drop the temporary large object storage table.
[0017] Optionally, the step of generating a temporary large object registration table according to the target session includes:
[0018] Generate the name of the temporary large object registration table based on the target session. The table name is used to find all temporary large objects corresponding to the target session.
[0019] Create a temporary large object registration table according to the table name, and fill the temporary storage target into the temporary large object registration table.
[0020] Optionally, the temporary large object registration table includes an identifier of the temporary large object, a temporary large object type, and at least one temporary large object column;
[0021] The steps of filling the temporary storage target into the temporary large object registration table include:
[0022] Generate a unique identifier according to the temporary storage target and use the unique identifier as an identifier;
[0023] Determine the temporary large object type of the temporary storage target and generate a corresponding type identifier;
[0024] Fill the type identifier in the temporary large object type column of the data row where the temporary storage target is located;
[0025] The reference information of the temporary storage target is filled into the corresponding temporary large object column according to the type identifier, and the reference information is the corresponding relationship between the temporary storage target and the temporary large object storage table.
[0026] Optionally, the step of establishing a temporary large object storage table includes:
[0027] The same number of temporary large object storage tables is established according to the number of temporary large object columns. The temporary large object storage tables are used to store description information and data of storage slices corresponding to the temporary large objects.
[0028] The data of the temporary storage target is split into multiple storage slices according to the preset splitting rules, and stored in the temporary large object storage table.
[0029] Optionally, the step of generating a table name of a temporary large object registration table according to the target session includes:
[0030] Generate a unique identifier based on the target session. The unique identifier is of UUID type.
[0031] A fixed identifier is added to the unique identifier according to a preset rule, thereby obtaining a table name of a temporary large object registration table.
[0032] According to another aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned methods for storing temporary large objects in a database are implemented.
[0033] According to yet another aspect of the present invention, a computer program product is provided, which includes a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned methods for storing temporary large objects in a database are implemented.
[0034] According to another aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements the steps of any of the above-mentioned methods for storing temporary large objects in a database when executing the machine executable program.
[0035] The storage method of temporary large objects in a database of the present invention first determines the target session in the database; then obtains the temporary large object to be stored in the target session as a temporary storage target; then generates a temporary large object registration table and establishes a temporary large object storage table according to the target session, the temporary large object registration table is used to record the reference information of the temporary storage target, and the temporary large object storage table is used to record the data of the temporary storage target and corresponds to the temporary large object registration table. Through this method, temporary large objects can be stored separately in the database, and the life cycle of the temporary large object is guaranteed to be consistent with the session, thereby avoiding the waste of database storage resources and improving the performance of the database.
[0036] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0038] Figure 1 is a schematic diagram of a table structure in a data table having a large object column according to an embodiment of the present invention;
[0039] Figure 2 is a schematic diagram of a system table in a data table having a large object column according to an embodiment of the present invention;
[0040] Figure 3 is a schematic diagram of an optional large object control block in a data table having a large object column according to an embodiment of the present invention;
[0041] Figure 4 is a schematic diagram of another optional large object control block in a data table having a large object column according to an embodiment of the present invention;
[0042] Figure 5 is a schematic diagram of an object and a storage slice table in a data table having a large object column according to an embodiment of the present invention;
[0043] Figure 6 is a schematic diagram of storing slices referencing each other in a data table with a large object column according to an embodiment of the present invention;
[0044] Figure 7 is a flow chart of a method for storing temporary large objects in a database according to an embodiment of the present invention;
[0045] Figure 8 is a schematic diagram of the structure of a temporary large object registration table of a method for storing temporary large objects in a database according to an embodiment of the present invention;
[0046] Fig. 9 is a schematic diagram of a temporary large object registration table of a storage method for temporary large objects in a database according to an embodiment of the present invention;
[0047] Fig.10 is a schematic diagram of a computer program product according to an embodiment of the present invention;
[0048] Fig.11 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and
[0049] Fig.12 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0050] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.
[0051] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0052] This embodiment provides a coordination method for long tasks in a database. Before describing the embodiment of the present application in detail, the database in this embodiment is first described to better understand the database environment on which this embodiment relies. The database environment not only supports the storage and operation of large objects, but also provides sufficient flexibility to perform complex rewriting tasks.
[0053] The database of this embodiment is established with a data base table, which can be a user base table and is created according to a creation statement. The data base table has at least one large object column, and at least part of the large object data items in the large object column are divided into multiple storage slices for storage. The data items in the large object column can be BLOB, CLOB / NCLOB or other types of variable-length binary data, character data, external data, etc. The data base table can be a user base table and is created according to a creation statement. The number of large object columns can be set according to business requirements, for example, set to one column, two columns, or more columns.
[0054] In the large object mode preset by the database, each large object column or each partition of the large object column is provided with a storage management table space, each storage management table space stores the object and storage slice table corresponding to the large object column or the large object column partition, and the object and storage slice table are used to store the description information and data of the storage slice.
[0055] In one example, the step of establishing a data base table includes: obtaining a creation instruction and generating a data base table according to the creation instruction, generating a column object identifier for each large object column or each partition of the large object column in the data base table; and naming the object and storage slice table according to the column object identifier to obtain a storage table object identifier. The creation instruction may use, for example, SQL (Structured Query Language). Taking a simple case as an example, assuming that a user has established a business table user_biz_data, which contains two large object columns col_x and col_y (and other regular data columns col_a and col_b) and the user has not set partitions for the large object columns, the creation statement may be:
[0056]
[0057] KLOB can be a large object data type defined in the database of this embodiment, which includes three proprietary base types: KBLOB, KCLOB, and KNCLOB, which correspond to the traditional BLOB, CLOB, and NCLOB types respectively. In the database of this embodiment, the existing Domain type mechanism can be used to set KBLOB, KCLOB, and KNCLOB as one of the replaceable implementations behind BLOB, CLOB, and NCLOB. This means that when the user specifies to use BLOB, CLOB, or NCLOB type when creating a table or defining a column, the proprietary base type KBLOB, KCLOB, or KNCLOB of this embodiment can actually be selected as an alternative.
[0058] The user creates a business table (base table) called user_biz_data, which contains two large object columns col_x and col_y that are not partitioned. This solution will automatically generate UUIDs (Universally Unique Identifiers) for these two large object columns.
[0059] The large object mode preset by the database can be a dedicated mode (Schema) created in the database. In some embodiments, the large object mode can be named sys_klob_schema, which defines the organization and structure of the database. For each large object column and its column partition in the user base table, the database system can establish a set of tables and indexes in the above Schema to store and manage large objects. The object itself will be divided into small storage slices (Chunks) and stored in these tables. It should be noted that the large object column can be partitioned as needed, and the large object column partition can be considered as a part of the large object column. Each large object column partition has an object and storage slice table. In some embodiments, when partitioning is not required, each large object column has an object and storage slice table.
[0060] For example, the sys_klob_sch Schema can set up matching object and storage slice tables for two unpartitioned large object columns col_x and col_y, named tab_colx_uuid and tab_coly_uuid respectively. The object and storage slice tables tab_colx_uuid and tab_coly_uuid generate globally unique identifiers using randomly generated UUIDs respectively. The format of the globally unique identifier can be a combination of a prefix (for example, the tab_ prefix mentioned above) and a UUID to meet the naming requirements of the database object name. The object record in the object and storage slice table is the first storage slice record of the object. In this embodiment, UUID is used to identify a large object column or a large object column partition, and data tables, indexes, and sequences can generate their own names by combining their own prefixes with UUIDs.
[0061] The large object column metadata table preset in the database system table records the description information of the object and the storage slice table. To manage large objects, the database system establishes a set of dedicated system tables to store the correspondence between the large object columns in the user table and these database objects, as well as the unique storage parameters of the large object columns. The large object column metadata table can be named sys_klob_column, which is one of a set of system tables configured for large objects in the database system.
[0062] The large object column metadata table sys_klob_column can also record the object identifier of the base table (used to identify the data base table, which can be named rel_oid and used when searching for metadata of the data base table) and the identifier of the large object column (which can be the column number of the large object column in the base table, used to locate the position of the large object column, which can be named attr_no, and can be used with rel_oid to uniquely identify a table column of the database, and is used when searching for table column metadata). In addition, the description information of the object and storage slice table recorded in the large object column metadata table includes the storage table object identifier (which can be named tab_oid, i.e., the OID of the above object and storage slice table. In the case of no partitioning, each large object column has a corresponding tab_oid. If the large object column is partitioned, each large object column partition has a corresponding tab_oid).
[0063] In the data base table, a large object control block is used to replace the position of the corresponding large object data item. The large object control block records at least the description information of the large object data item and the data item object identifier. That is, in the final data base table, the position of the large object data item is a control block. The control block can be set to different data structures according to the size of the large object data, and at least includes the description information of the large object data item and the data item object identifier. The description information of the large object data item is used to describe the type, various flags, version, etc. of the large object data item. The data item object identifier is a fixed unique identifier of the object, which is a UUID type identifier, randomly generated when the object is created, and remains unchanged throughout the life cycle of the object.
[0064] A set of system tables specially configured for large objects in the database system may also include: storage parameter history table (which may be named sys_klob_store_params), deduplication task history table (which may be named sys_klob_dedup_tasks), and in addition, the system metadata table in the database system table (which may be named pg_attribute) also records other basic attributes of large object columns that are consistent with other regular data types.
[0065] In some embodiments, the storage parameter history table sys_klob_store_params preset in the database system table records the storage table object identifier tab_oid and storage parameters of the object and the storage slice table, and these storage parameters may include storage parameter version number, storage options, encryption parameters, task identifiers, etc. The data in the storage parameter history table sys_klob_store_params can be used when the storage options such as compression and encryption of large objects are modified or when existing data needs to be recreated.
[0066] In some embodiments, the deduplication task history table sys_klob_dedup_tasks preset in the database system table records the storage table object identifier tab_oid of the object and the storage slice table and the deduplication task information, wherein the deduplication task information includes the deduplication task sequence number and the deduplication task identifier, which is used to determine the execution status of the deduplication task.
[0067] The original system tables of the database system tables also store the metadata of the tables and indexes used for large object storage, which is basically consistent with the metadata records of other common data types and will not be elaborated here.
[0068] Each storage management tablespace also stores the primary key index of the object and storage slice table. The primary key index is used to search for large object data items and / or storage slices in the object and storage slice table; and the large object column metadata table also records the information of the primary key index. The primary key index can generally be hash indexed. The search efficiency is improved by establishing an index.
[0069] A reference column is also provided in the object and storage slice table. The reference column is used to record the reference relationship between the storage slice and other storage slices and / or the reference relationship between the large object data item and other large object data items. By utilizing these reference relationships, repeated storage of the same large object data item and / or storage slice can be avoided, saving storage space resources. Furthermore, each storage management table space can also store a reference column index of the object and storage slice table. The reference column index is used to query the reference relationship in the object and storage slice table; and the large object column metadata table also records the reference column index information. The storage efficiency of finding reference relationships is improved by establishing a reference column index.
[0070] Since rewriting data and deduplication of large objects when modifying storage options requires a lot of execution time, in order to minimize the impact on the user's daily business, the above operations are generally performed gradually in the background. In order to ensure the correct execution of the above operations, in some embodiments, a data rewriting task sequence (store_seq_<col / part uuid> ) and the deduplication task sequence (dedup_seq_<col / part uuid> ). The data rewriting task sequence is used to record the rewriting process of objects and storage slice tables, and the deduplication task sequence is used to record the deduplication process of objects and storage slice tables, so that these two sequences can be used to track the tasks of rewriting data and deduplication of large objects when modifying storage options.
[0071] In this embodiment, in order to achieve efficient storage and management of large objects, especially when processing TB-level large objects, a storage environment design based on tables and indexes is adopted. This method avoids complex transformation of the underlying storage implementation mechanism of the database, and instead sets a storage management table space for each large object column or each large object column partition in the large object mode preset in the database.
[0072] The following is an example of creating a business table user_biz_data that contains two large object columns col_x and col_y. Figure 1 The diagram is a schematic diagram of a table structure in a data table with a large object column according to an embodiment of the present invention.
[0073] When the user creates the data base table (business table) user_biz_data, the database system generates UUIDs (colx_uuid and colly_uuid) for the col_x and col_y large object columns contained in it. When generating database objects, prefixes are added to the corresponding UUIDs. On the one hand, some UUID text forms have a number as the first character, which does not conform to the database object naming rules; on the other hand, a group of database objects, including tables, indexes, and sequences, are used to store a large object column or column partition. Sequences are indeed objects used to generate auto-increment sequence values in the database, and are usually used to provide unique identifiers for records in a table. In this solution, sequence numbers are generated for rewrite tasks and deduplication tasks respectively, the main purpose of which is to identify the execution order of these tasks. Since these sequence numbers are generated within a specific column or column partition range, and considering that the number of executions of these two types of tasks is usually not too many, the possibility of sequence value wrapping (i.e., the sequence value restarts after reaching the upper limit) is indeed very small. This ensures that the sequence numbers are unique within these ranges. In addition, these sequence numbers are not globally unique identifiers like UUIDs. UUID is usually used to generate globally unique identifiers. No matter where it is generated, the probability of conflict of UUID is very low. Sequence-generated unique identifiers are only valid in a specific context or range, and may no longer be unique beyond this range. If col_x and col_y are partitioned, each partition has its own UUID. In addition, regular data type columns col_a and col_b are stored according to the original storage logic.
[0074] The structure of the entire database includes: system metadata schema pg_catalog schema, application schema schema, and large object schema sys_klob_schema. The system metadata schema pg_catalog schema is the database metadata, and the application schema schema and large object schema sys_klob_schema are mainly user business data.
[0075] In the system tables, the relational attribute table (or system metadata table, which can be named pg_attribute) is used to store the common basic attributes of the database's general data types and data tables (including the basic attributes of large object columns that are consistent with other regular data types), the large object column metadata table sys_klob_column, the storage parameter history table sys_klob_store_params, and the deduplication task history table sys_klob_dedup_tasks as the unique storage attributes of big data. The large object column metadata table sys_klob_column records the OID of the created table and index, as well as the unique storage attributes of the large object column. The base table OID (rel_oid) and large object column number (attr_no) fields in the table are used to associate with the original system tables in the database, indicating which column in which data base table this row of data records the attributes of.
[0076] In order to track the execution status of long-term tasks such as deduplication tasks and rewriting existing data when modifying large object column storage options, and to ensure recovery from interrupted tasks, the storage parameter history table sys_klob_store_params and the deduplication task history table sys_klob_dedup_tasks are used to record the history of storage parameters and deduplication task parameters.
[0077] The large object schema sys_klob_schema includes col_x data storage tablespace and col_x data storage tablespace. If the large object column has partitions, each partition has its own data storage tablespace. Taking col_x data storage tablespace as an example, in addition to data storage of col_x objects and storage slice tables, indexes (which can be hash indexes) are also created for the primary key and reference columns of the objects and storage slice tables.<colx_uuid> ,ref_<colx_uuid> .
[0078] col_x object and storage slice tables can be named with the prefix tab_ plus colx_uuid to store object records and storage slice records. Both are globally uniquely identified by a randomly generated UUID. The object record is essentially the first storage slice (Chunk) record (Chunk) of the object.<colx_uuid> Primary key index idx_<colx_uuid> It can be used to quickly find objects or store slices of Chunks. When object deduplication is supported, objects are allowed to reference other objects and Chunks to reference other Chunks.<colx_uuid> Reference column index ref_<colx_uuid> It can be used to speed up the query operation of reference relationship.
[0079] In the base table user_biz_data, the location of the large object data item will be replaced by the large object control block, which will contain the actual storage location of the large object data item. In some embodiments, if the data size of the large object data item is very small, in order to optimize performance, the data item with small data size can also be directly stored in the large object control block according to the user's choice.
[0080] Figure 2 This is a schematic diagram of a system table in a data table with a large object column according to an embodiment of the present invention. There are four main system tables related to large object columns: large object column metadata table sys_klob_column, relationship attribute table pg_attribute, storage parameter history table sys_klob_store_params, and large object column deduplication task history table sys_klob_dedup_tasks.
[0081] The relation attribute table pg_attribute is used to record table column metadata. Like other columns of regular data types, the basic attributes of large object columns are also stored in this table. The data base table OID rel_oid and the column number attr_no of the large object column in the base table can be used to locate the position of the large object column in the data base table.
[0082] The large object column metadata table sys_klob_column is used to store the unique attributes of the large object column and its column partitions. It is associated with the relational attribute table pg_attribute through the two fields: the data base table OID rel_oid and the column number attr_no of the large object column in the base table. If the large object column is not partitioned, each record in the relational attribute table pg_attribute has a corresponding record in the large object column metadata table sys_klob_column. If the large object column is partitioned, each partition will also have a corresponding record in the large object column metadata table sys_klob_column.
[0083] Specifically, the large object column metadata table sys_klob_column can include the following attributes:
[0084] The data base table OID rel_oid is used when searching for metadata related to the base table.
[0085] The column number attr_no of the large object column in the base table can be used with rel_oid to uniquely identify a table column in the database and is used when looking up table column metadata.
[0086] Object and storage slice table OID tab_oid, used to store the OID of the large object and its storage slice table. If the large object column is not partitioned, each large object column corresponds to such a table. If the large object column is partitioned, each partition also corresponds to such a table.
[0087] Primary key index OID idx_<colx_uuid> , the OID of the index (which can be a hash index) of the primary key column unit_id of the object and storage slice table. When the large object column is not partitioned, each large object column corresponds to a primary key index. When the large object column is partitioned, each partition also corresponds to such an index.
[0088] Reference column index OID ref_<colx_uuid> : The OID of the index (hash index) of the object / storage slice identification column ref_id used in the object and storage slice table. If the big object column is not partitioned, each big object column corresponds to such an index. If the big object column is partitioned, each partition also corresponds to such an index.
[0089] The tablespace OID tbs_oid is the OID of the tablespace where the object and the slice table and its index are located. Large object columns can be placed in different tablespaces from other data, or each column partition can be placed in a different tablespace. If needed, a separate tablespace can be specified for each large object column (unpartitioned) or large object column partition (partitioned).
[0090] The storage parameter version number sequence OID store_seq_oid is the storage parameter version number sequence store_seq_<col / part uuid> The OID of the store_seq_ sequence is used to generate integers that identify the versions of the large object storage parameters and their order. Each large object column (in the case of non-partitioning) or large object column partition (in the case of partitioning) corresponds to such a sequence object.
[0091] The deduplication task sequence OID dedup_seq_oid is the deduplication task sequence dedup_seq_oid for the large object column or large object column partition.<col / part uuid> The OID of the deduplication task sequence dedup_seq is used to generate an integer to identify the version of the large object deduplication task parameters and their order. Each large object column (in the case of no partition) or large object column partition (in the case of partition) corresponds to such a sequence object.
[0092] The physical size of the storage slice chunk, chunk_size, is used to record the size of the storage slice Chunk of the large object. The unit is bytes. The Chunk size is not limited by the size of the underlying storage page and can be selected between 2K and 1G. The Chunk size is set separately for each large object column (unpartitioned) or large object column partition (partitioned) to meet the requirements of different large data columns.
[0093] The current storage option lob flags is the current storage option. This can be a 32-bit bit string, which contains storage options such as storage location, compression, and encryption. The storage parameter history table sys_klob_store_params also fully records the storage options of each version. In order to speed up some operations, the current storage option lob flags retains a redundant field and is stored repeatedly;
[0094] The current storage parameter version number store ver is the latest serial number generated by the large object column / partition storage parameter version number sequence. It is used together with tab_oid to identify which record in the system table sys_klob_store_params the current storage parameter corresponds to.
[0095] dedup_ord: current deduplication task number, which is the latest serial number generated by the large object column or large object column partition deduplication task serial number sequence. It is used together with tab_oid to identify which record in the large object column deduplication task history table sys_klob_dedup_tasks the current deduplication task corresponds to.
[0096] Partition strategy partstrat, used to record the partition strategy. The partition strategy can include h hash partition, l list partition, r range partition table. This attribute has a value only in the row corresponding to the object and the storage slice partition table;
[0097] The number of columns in the partition key, partnatts; only has values in the row corresponding to the object and the Chunk partition table;
[0098] Default partition partdefid: The OID of the pg_class entry for the default partition of this partitioned table, or zero if this partitioned table has no default partition. This value is present only in rows corresponding to objects in Chunk partitioned tables;
[0099] The partition key column number vector partattrs is an array of length partnatts values indicating which table columns are part of the partition key. For example, the value 1 3 indicates that the first and third table columns form the partition key. A zero in this array indicates that the corresponding partition key column is an expression rather than a simple column reference, and is only present in the row corresponding to the object and the storage slice partition table;
[0100] Partition key operator class OID vector partclass. For each column in the partition key, this field contains the OID of the operator class to use. It has a value only in the row corresponding to the object and the storage slice partition table.
[0101] Partition key column collation OID vector partcollation. For each column in the partition key, this field contains the OID of the collation to be used for partitioning. If the column is not a sortable data type, the corresponding value is zero. It only has a value in the row corresponding to the object and the storage slice partition table.
[0102] Partition key column expression tree partexprs, expression tree of partition key columns that are not simple column references (expressed in nodeToString()), which is a list with one element for each zero item in partattrs. If all partition key columns are simple column references, this field is empty. There is a value only in the row corresponding to the object and the Chunk partition table;
[0103] The internal representation of a single partition boundary, relpartbound, is the internal representation of the partition boundary and has values only in the rows corresponding to the column partition.
[0104] The large object column-specific storage parameter history table sys_klob_store_params is used to save all historical versions of each large object column-specific storage parameter in the database library, and is associated with the records in the sys_klob_column table through the tab_oid column. These historical data are used when modifying the compression, encryption and other storage options of large objects and need to rewrite existing data.
[0105] Specifically, the large object column-specific storage parameter history table sys_klob_store_params can include the following attributes:
[0106] Object and storage slice table OID tab_oid;
[0107] The storage parameter version number store_ver is defined by the aforementioned tab_oid as store_seq_<col / part uuid> The sequence generation;
[0108] The storage option lob flags can be used to identify the off-line storage method (including table storage method, file storage method, OSS (Object Storage Service) storage method, etc.), whether in-line storage is available (available or unavailable), whether encryption is available (encrypted or not), the compression level (not compressed, low-level compression, medium-level compression, high-level compression), and the encryption algorithm identifier (encryption algorithm type). The contents of the above identifiers respectively occupy one or more identification bits of the storage option lob flags. In some embodiments, the storage option lob flags can be a 32-bit bit string, which is spliced by the above identification bits.
[0109] Key expiration UTC time key_expr, the expiration time of the key used to encrypt the large object column, can be in UTC time (Coordinated Universal Time);
[0110] The key enc_key is the key for encrypting large object columns. It is stored in ciphertext and encrypted with the parent key.
[0111] The encryption & compression task identifier enc_task_id is the identifier of the large object column encryption and compression task. It can be an identifier in the form of a UUID, which is randomly generated when creating a large object column encryption and compression task and registered in a hash table in the memory. If the identifier recorded in the table cannot be found in the encryption and compression task registration table in the current memory, it means that the process executing this encryption and compression task has exited.
[0112] The tab_oid and store_ver fields in the large object column-specific storage parameter history table sys_klob_store_params can be combined to uniquely identify a storage parameter version of a large object column or large object column partition in a library.
[0113] The large object column deduplication task history table sys_klob_dedup_tasks saves the parameters of each deduplication task for each large object column in the database. It is associated with the records in the sys_klob_column table through the tab_oid column to determine the execution status of the deduplication task.
[0114] Specifically, the large object dedup task history table sys_klob_dedup_tasks can include the following attributes:
[0115] Object and storage slice table OID tab_oid, meaning is the same as the tab_oid attribute of other system tables above;
[0116] The deduplication task sequence number dedup_ord is composed of the object and storage slice table OID as the large object column or large object column partition deduplication task sequence dedup_seq_<col / part uuid> The sequence generation;
[0117] The unique identifier of the deduplication task process group, dedup_task_id, is a UUID format identifier, which is randomly generated when creating a large object column deduplication task and registered in a hash table in memory. If the identifier recorded in the table cannot be found in the deduplication task registration table in the current memory, it means that the process executing this deduplication task has exited.
[0118] The dedicated system tables established above record the description information of the object and the storage slice table. These dedicated system tables are used to store the correspondence between the large object columns in the user table and the database objects used to store large objects, as well as the unique storage parameters of the large object columns, making data management more efficient and in line with the storage management characteristics of large objects.
[0119] In the solution of this embodiment, a large object control block is used to replace the position of the corresponding large object data item in the data base table. The large object control block can include two types: an in-row large object storage structure and an out-of-row large object storage structure.
[0120] Figure 3 The diagram is a schematic diagram of an optional large object control block in a data table having a large object column according to an embodiment of the present invention. Figure 3 The out-of-row large object storage structure is shown. The large object control block varattrib_4b includes a file header varattrib_4b.va_header and data varattrib_4b.va_data. The data varattrib_4b.va_data includes the description information of the large object data item (LOB object control block description word) and the data item object identifier (LOB object fixed unique identifier).
[0121] The description information of the large object data item may describe the control block type (inline or outline), flags such as whether there is data in the line, control block format version number, etc. The above contents may respectively occupy one or more flags of the description information. In some embodiments, the description information of the large object data item may be a 32-bit bit string, which is formed by concatenating the flags corresponding to the above descriptions.
[0122] The data item object identifier is a UUID type identifier that is randomly generated when the object is created and remains unchanged throughout the life cycle of the object.
[0123] The out-of-row large object storage structure only contains the LOB object control block descriptor and the LOB object fixed unique identifier. These two fields remain unchanged throughout the life cycle of the object, avoiding the need to update the data base table when updating the large object content.
[0124] Figure 4 The diagram is a schematic diagram of another optional large object control block in a data table having a large object column according to an embodiment of the present invention. Figure 4 The in-line large object storage structure is shown.
[0125] The in-row large object storage structure is for large object data items with a small amount of data (e.g., within 32k). It stores large object data in the control block (the maximum size of the large object data is within a set range, e.g., a maximum of 32k). In addition to the LOB object control block descriptor and the LOB object fixed unique identifier, the data varattrib_4b.va_data further includes: LOB object storage options and LOB data. The LOB object storage option can be a bit string, which can use the same format as the lob_flags field in the system table sys_klob_column and sys_klob_store_params. LOB data contains the data of the large object.
[0126] By distinguishing between the in-row large object storage structure and the out-of-row large object storage structure, the storage requirements of large object data items of different data sizes are met, and only data exceeding a certain data size (for example, 32k) is stored out-of-row.
[0127] The object and storage slice table is a table that actually stores large object data. During database operation, each large object column or column partition is equipped with an object and storage slice table. This embodiment optimizes and improves the object and storage slice table, which is significantly different from the existing PostgreSQL and has obvious advantages.
[0128] In the PostgreSQL database solution, the large object storage table pg_largeobject is a system table that is only used to store slice data. It contains three fields: loid, pageno, and data. Among them, loid is the unique identifier of the large object, the type is OID (4-byte unsigned integer), and it is unique within the database. Pageno identifies the page number of the chunk data in the large object (starting from 0), and the type is a 4-byte integer. Data is the chunk data, and the volume does not exceed 1 / 4 of the database storage page size. For the common 8K storage page setting, its size does not exceed 2K.
[0129] In the PostgreSQL database, the total capacity of large objects in the entire database is limited by the upper limit of the data volume of a single table, and the total number of objects in the entire database is limited by the range of OID values. If the user's business table uses data types with a larger value range, such as int8, the number of large object identifiers may not be enough. Moreover, this type of OID identifier can only ensure uniqueness within a database. If you want to import a large object into another database, you must reallocate the identifier, which is not conducive to tracking large objects. Each row of a large data object stores the data of a page of a large object, starting from the byte offset (pageno*LOBLKSIZE) inside the object. Sparse storage is allowed, and pages may be lost and may be shorter than LOBLKSIZE bytes (even if it is not the last page). A lost area in a large object will be read as 0. In other words, this solution does not support insertion or deletion operations in the middle of a large object, but only supports content appending and replacement. Its behavior mode is different from the generally understood editing operation.
[0130] Figure 5 : This is a schematic diagram of an object and storage slice table in a data table with a large object column according to an embodiment of the present invention. In the scheme of this embodiment, there are two types of records stored in the object and storage slice table. The first type is an object record, which contains object metadata and data within the first 32K (for example, it can be set to other values), which is used to accelerate the operation of some functions. For objects larger than 32K (for example, it can be set to other values), it also contains a storage slice index block, which is used to find out which storage slices the data read and written by the user is located in. The second type is a storage slice record, which contains storage slice metadata and data above 32K. A large object (more than 32K) will consist of an object record and several storage slice records. For each large object column or column partition, the size of the storage slice can be freely selected within 1G. If the average size of the objects in the column is small, it is suitable to use a smaller storage slice data size; if the average size of the objects in the column is large, it is suitable to use a larger storage slice size. For example, for TB-level large objects, the largest storage slice size (1GB) can be used.
[0131] Specifically, the object and storage slice table can include the following attributes:
[0132] The object's fixed unique identifier, uint_id, is a UUID-type unique identifier. For object records, this is the object identifier, and for storage slices, this is the storage slice identifier. UUID-type identifiers can be considered unique in any case. Even if an object is imported into other databases, this identifier can remain unchanged and no conflict will occur.
[0133] part_key is the partition key used internally by the system and can be a signed integer. When the user chooses to use other columns in the base table as the partition key of the large object column, the original partition setting made by the user will be translated into an internal list partition format. This field contains the partition key used internally. When the user chooses to perform Hash partitioning based on the object / storage slice identifier, this field can be NULL.
[0134] store_ver is the storage parameter version number of the object. It is NULL in the storage slice record. This field can also be used to distinguish object records from storage slice records.
[0135] ref_id, for object records, if there is a value, it is the identifier (UUID) of the referenced object, indicating that the object is exactly the same as the referenced object; for storage slice records, if there is a value in this field, it is the identifier (UUID) of the referenced storage slice, indicating that the storage slice is exactly the same as another storage slice. When this field is not NULL, the prefetch and ext_data fields of the record are both NULL. In addition, only when one object is exactly the same as another object, can there be a reference relationship between the two. If only some storage slices are the same, there is only a reference relationship between the storage slices, and there is no reference relationship between the objects.
[0136] ref_count, in the object record, represents the number of times this object is referenced by other objects; in the storage slice record, represents the number of times this storage slice is referenced by other storage slices. If the object or storage slice is not referenced, the value of this field is 0.
[0137] dedup_feat is the deduplication feature value of the storage slice itself in the storage slice record, and the deduplication feature value of the entire object in the object record. This is a binary data block, and its length is determined by the deduplication feature value algorithm. If the deduplication function has never been enabled on the corresponding column or column partition, this field is NULL (initial state). For small objects stored out of row, if DML operations change the object content, then when the DML operation occurs: 1. If deduplication is not currently enabled, set this field to NULL; 2. If deduplication is currently enabled, generate a new object feature value and fill it in this field; for large objects stored out of row, if DML operations change the content of its subordinate slices, then when the DML operation occurs: 1. If deduplication is not currently enabled, set this field to NULL; 2. If deduplication is currently enabled, generate a new slice feature value and fill it in this field. When the deduplication task is executed, feature values will be generated for small objects that do not have feature values and slices of large objects, and filled in this field.
[0138] prefetch, in the object record, is the data within the first 32K of the object, which is stored according to the object storage parameter settings and may be compressed and encrypted; in the storage slice record, this field is always NULL.
[0139] ext_data, in the object record, this additional data field contains the storage slice index block, records the arrangement order of all storage slices of the object, the original data logical length and unique identifier. The logical length here refers to the length calculated in the unit of the original data. For BLOB, the unit is bytes, and for CLOB / NCLOB, the unit is characters. In the storage slice record, this field contains the data of the part above 32K of the large object. Both the storage slice index block and the storage slice data will be stored according to the setting of the object storage parameters, and may be compressed and encrypted. For example, in the record of the first storage slice of a large object, the additional data field can be used to store the index records of all storage slices corresponding to the large object, that is, the storage slice index block. In the storage slices other than the first storage slice of the large object, the additional data field is used to store the data of the corresponding storage slice. That is, only the first storage slice of the large object is used to store the storage slice index block in the additional data field, and its own data is stored in the prefetch field, and the remaining storage slices will store their own corresponding data content in the additional data field of ext_data. Whether storing slice index blocks or slice data, they will be stored according to the settings of the object storage parameters, and may be compressed and encrypted. Under the above storage structure, the storage slice content modification method of this solution is significantly different from the PostgreSQL database in the prior art. It can efficiently support insertion and deletion operations in the middle of large objects and adopt the same semantics as string insertion and deletion operations.
[0140] In the object record (i.e. the first data row of the object), the prefetch field is used to store the first slice of the object, i.e. the data of limited length in the object header. In some scenarios, this part of data can be directly read and written like a regular field without going through a file-based API; its length limit is also low, unlike subsequent slices which can be set to be very large; the ext_data field is used to store the slice index block. In the slice record (i.e. the data row where the second and subsequent slices are located), the prefetch field is not used and is set to NULL; the ext_data field is used to store the data content of the slice.
[0141] Through the above database design method, when a large object is split into multiple storage slices, first, the global unique identifier of the large object itself can be determined in the data base table (that is, the user_biz_data table), and the first storage slice where it is located can be found in the object and storage slice table according to the global unique identifier of the large object (the global unique identifier of the large object is the slice unique identifier of the first storage slice); then, the global unique identifier of the target storage slice where the target data is located is determined through the storage slice index block recorded in the first storage slice, and then the target storage slice is found in the object and storage slice table through the global unique identifier of the target storage slice, and finally the specific data of the target storage slice is obtained in its ext_data column.
[0142] In addition, if you want to modify the data of the target storage slice, you can also find the corresponding target storage slice and perform the operation according to the above method, and then synchronously update the content of the storage slice index block in the additional data field of the first storage slice.
[0143] The index block of the storage slice is a binary data block that contains the location information of all the storage slices of an object, which includes the following fields in sequence: storage slice index library format description word, storage slice number, storage slice length array, and storage slice identification array.
[0144] The storage slice index library format description word can be a signed integer, used as a bit string, some of its bits (such as the lower 8 bits) are the storage slice index block format version number, and the other bits can be reserved.
[0145] The total number of storage slices, that is, the length of the subsequent storage slice array, the type is a signed integer. If this field is 0, it means that no storage slice is included.
[0146] The length of the storage slice array is the total number of storage slices mentioned above. The array element type is a signed integer and is arranged in the order of the storage slices in the object.
[0147] Storage slice identifier array, the length is the total number of storage slices, the array element type is UUID number, and it is also arranged in the order of storage slices in the object.
[0148] from Figure 5 As can be seen in the figure, in the storage slice index block, the metadata (length and identifier) of the storage slice is not stored by row, but by column, that is, all storage slice length values are stored continuously first, and then all storage slice identifier values are stored continuously. Since large objects are usually updated less frequently, there will be many repeated values in the length value of their storage slices, which helps to improve the compression rate.
[0149] In the solution of this embodiment, the metadata (identification, length, etc.) of the storage slice is stored separately from the data, the actual length of the storage slice is variable, and the order of the storage slices in the large object is recorded by the storage slice index block. Therefore, when inserting or deleting data in the middle of the large object, only the storage slice involved in the inserted or deleted data needs to be rewritten, and other storage slices are not moved, which greatly reduces the amount of data that needs to be rewritten during the update and improves performance.
[0150] In comparison, the PostgreSQL database uses fixed-length storage slices, and the storage slice metadata and data are saved in one record. The position of the storage slice sequence number is used to indicate its position in the object. If data is inserted or deleted from the middle, all storage slices after the insertion / deletion point need to be rewritten, and the performance is far inferior to the solution of this embodiment.
[0151] By adding reference object / storage slice uint_id, ref_id, and ref_count, the large object storage of the solution of this embodiment supports deduplication operations, that is, simplifying duplicate objects or storage slices. Figure 6 It is a schematic diagram of storage slices referencing each other in a data table with a large object column according to an embodiment of the present invention. For example, some storage slices of a large object data item A are the same as storage slices in another large object data item B. These storage slices are relatively independent and have unique identifiers, but do not store actual data, but store the identifier of the storage slice of the object data item B. For example, when storage slice 102 is the same as storage slice 201, and storage slice 104 and storage slice 105 are the same as storage slice 204, the identifier of storage slice 201 is stored in storage slice 102, and storage slice 104 and storage slice 105 respectively store the identifier of storage slice 204. Storage slice 201 and storage slice 204 respectively record reference counts.
[0152] Similarly, if a large object data item D is the same as another large object data item C, then large object data item D can store the identifier of large object data item C without storing the data. Large object data item C records the reference count. Of course, this is only for large object data items with a volume of less than or equal to 32K. For larger large object data items, since the cost of determining whether they are duplicated as a whole is too high and the probability of a complete match is low, it is a better choice to only remove duplicates at the granularity of storage slices.
[0153] The reference count of the above records can avoid data errors when modifying data or executing DML.
[0154] Using the above storage structure, the storage forms of large objects can be divided into three types: small objects stored in-line, small objects stored out-of-line, and large objects stored out-of-line.
[0155] The metadata and data body of the small objects stored in the row are stored in the row of the data base table in the form of an in-row control block. The small objects stored in the row have a compact structure and occupy a small space.
[0156] Part of the metadata of small objects stored out of line is stored in the data base table row, and the remaining metadata and data body are stored in the object and storage slice table in the form of an out-of-line object control block and an object record. In addition to the control block and the object data itself, small objects stored out of line also contain fields that support other features such as partitioning, deduplication, and progressive background tasks.
[0157] Part of the metadata of a large object stored out-of-line is stored in-line, the remaining metadata, the first 32K data, and the storage slice index block are stored in one object record, and the data above 32K is stored in a group of storage slice records. A large object stored out-of-line consists of one object record and several storage slice records. The object record and several storage slice records are stored in the same table, using the same primary key column. The object record serves as the entry point to access the large object data.
[0158] It is worth noting that although large objects stored out-of-row also have fields that support partitioning, deduplication, and progressive background tasks, as well as other features of the above-mentioned small objects, the differences are: 1. In the object records of large objects, ref_id, ref_count, and dedup_feat are not used, because large objects are not deduplicated as a whole, but only slice-level deduplication; 2. In the slice records of large objects: store_ver is not used, because all contents of a single object use unified storage parameters, which is more in line with the general expectations of users; prefetch is also not used, because when users read and write specified fragments in large objects, they do not need to quickly obtain a small piece of data at the head of the slice.
[0159] During the operation of the database, it is sometimes necessary to create some temporary large objects. They do not belong to any user business table (base table). Therefore, after the Session is started, such temporary large objects need to be stored separately to avoid temporary large objects still being stored in the database after the Session ends, wasting database storage space and other resources.
[0160] In order to solve the above problems, the present invention provides a storage method of temporary large objects in a database. Figure 7 FIG. 1 is a flow chart of a method for storing temporary large objects in a database according to an embodiment of the present invention. Figure 7 As shown, the storage method of the temporary large object in the database at least includes the following steps S701 to S705.
[0161] Step S701, determine the target session in the database. In some optional embodiments, Session is a core concept in the database management system, which represents an interactive process between the client and the database server. During a database session, the user (or application) can perform a series of operations, such as query, insert, update, delete data, etc., and the database will maintain the state of this session, including but not limited to user authentication information, transaction context, session variables, etc. During the session, some temporary large objects are sometimes generated. Such temporary large objects will lose their function after the session ends, so a corresponding temporary large object storage method is established for this database. Among them, the target session is a session that generates temporary large objects during the session.
[0162] Step S702: Acquire a temporary large object to be stored in the target session as a temporary storage target.
[0163] Step S703: Generate a temporary large object registration table according to the target session. The temporary large object registration table is used to record reference information of temporary storage targets.
[0164] Step S704: Create a temporary large object storage table. The temporary large object storage table is used to record data of temporary storage targets and corresponds to the temporary large object registration table.
[0165] This method can be used to store temporary large objects separately in the database, and ensure that the life cycle of the temporary large objects is consistent with the session, thereby avoiding waste of database storage resources and improving database performance.
[0166] In some optional embodiments, after the step of establishing a temporary large object storage table, the following steps may be generally included: setting a life cycle for the temporary storage target, the life cycle of the temporary storage target is determined by the life cycle of the variable bound to the temporary storage target; when the life cycle is reached, deleting the temporary storage target. During use, the temporary large object created by the target session will also lose its function after the target session ends. In most cases, the temporary large object will lose its function when the variable bound to the temporary large object in the target session ends. Therefore, this solution preferably chooses to bind the life cycle of the temporary storage target with the life cycle of the variable bound to the temporary storage target, so as to delete the temporary storage target as soon as possible to save database space resources.
[0167] Optionally, after the step of establishing the temporary large object storage table, the step further includes: deleting the temporary large object storage table when the target session ends. In the actual execution process, some variables may be stored until the target session ends before disappearing. In order to ensure that the temporary large objects can be deleted normally, this solution chooses to bind the life cycle of the temporary storage directory and the target session together to ensure that all the corresponding temporary large objects can be synchronously deleted when the target session ends, thereby saving the storage space resources of the database.
[0168] In some optional embodiments, the step of generating a temporary large object registration table according to the target session may generally include: generating a table name of the temporary large object registration table according to the target session, the table name is used to search for all temporary large objects corresponding to the target session; creating a temporary large object registration table according to the table name, and filling the temporary storage target into the temporary large object registration table. In the database of this solution, the data storage method of ordinary large objects is as follows Figures 1 to 6 As shown in the figure, due to the particularity of temporary large objects, a temporary large object registration table is designed. The basic structure of the temporary large object registration table is similar to the data base table, but it has been partially simplified. The table name of the temporary large object registration table corresponds to the target session one by one, so that each target session corresponds to a temporary large object registration table. The temporary large object registration table records the information of all temporary large objects generated by the target session. Through this solution, all temporary large objects corresponding to different target sessions can be quickly queried.
[0169] Optionally, the temporary large object registration table may generally include an identifier of the temporary large object, a temporary large object type, and at least one temporary large object column. The steps of filling the temporary storage target into the temporary large object registration table may generally include: generating a unique identifier based on the temporary storage target, and using the unique identifier as an identifier; determining the temporary large object type of the temporary storage target and generating a corresponding type identifier; filling the type identifier into the temporary large object type column of the data row where the temporary storage target is located; filling the reference information of the temporary storage target into the corresponding temporary large object column based on the type identifier, the reference information being the correspondence between the temporary storage target and the temporary large object storage table. The reference information may be the large object data item in the above-mentioned data base table, or it may be a large object control block. The specific structure of the large object control block is as follows: Figure 3 and Figure 4 The above has been explained and will not be repeated here. Those skilled in the art can determine the specific content of the reference information according to actual conditions.
[0170] Some optional examples of temporary large object types include BLOB, CLOB, and NCLOB. BLOB (Binary Large Object) is mainly used to store binary data, such as images, audio, video files, or any non-text binary data. CLOB (Character Large Object) is used to store large amounts of character data and is suitable for text information, such as long texts, reports, or XML documents. NCLOB (National Character Large Object) is used to store large amounts of multi-byte character data, such as text that supports Unicode.
[0171] In order to accommodate all types of temporary large objects, in addition to setting the temporary large object identifier column, the temporary large object registration table also sets corresponding type identifiers according to different types, and then fills its reference information into the temporary large object column of the corresponding type. Those skilled in the art can set the same number of temporary large object columns according to the number of types of temporary large objects in actual use, and each temporary large object records its reference information into the corresponding temporary large object column when recording, and other temporary large object columns can be set to empty in this row.
[0172] In the database, different types of temporary large objects are stored in different types of data, so the same number of temporary large object storage tables are set up according to the number of temporary large object types. The storage structure of the temporary large object storage table is basically similar to the above-mentioned object and storage slice table. Those skilled in the art can set the storage structure of the temporary large object storage table according to actual conditions.
[0173] Optionally, the step of establishing a temporary large object storage table may generally include: establishing the same number of temporary large object storage tables according to the number of temporary large object columns, the temporary large object storage table is used to store the description information and data of the storage slices corresponding to the temporary large object; dividing the data of the temporary storage target into multiple storage slices according to the preset splitting rule, and storing them in the temporary large object storage table. An optional example of the preset splitting rule is as follows: when the data volume of the temporary large object is greater than the set size (for example, 32K), it is split into multiple storage slices. Those skilled in the art can determine the preset splitting rule according to the actual situation. By dividing the data body of the temporary large object into multiple storage slices, and setting an independent slice record for each slice in the temporary large object storage table, distributed storage and management of data is realized. This method not only optimizes the use of storage space, but also can adapt to the growth of data volume and changes in storage requirements, but also facilitates operations such as data backup, recovery and migration, and improves the security and reliability of data.
[0174] In some other optional embodiments, the step of generating the table name of the temporary large object registration table according to the target session may generally include: generating a unique identifier according to the target session, the unique identifier being of UUID type; adding a fixed identifier to the unique identifier according to a preset rule, thereby obtaining the table name of the temporary large object registration table. This method can create a unique identifier for each target session, and by splicing the fixed identifier with others, the spliced identifier can be represented as a temporary large object corresponding to the target session and can be distinguished from the identifiers of other target sessions.
[0175] In addition, it should be noted that those skilled in the art may also directly record the data of the temporary large object into the large object column in the temporary large object registration table when the data volume of the temporary large object is small, thereby further simplifying the process.
[0176] Figure 8 The diagram is a structural diagram of a temporary large object registration table of a method for storing temporary large objects in a database according to an embodiment of the present invention. Fig. 9 FIG. 1 is a schematic diagram of a temporary large object registration table of a storage method for temporary large objects in a database according to an embodiment of the present invention. In some optional embodiments, taking BLOB, CLOB and NCLOB as examples, the temporary large object registration table can be designed as follows: Figure 8 The structure shown, specifically, the temporary large object registration table tmp_<random uuid> The following attributes can be included:
[0177] First, the table name of the temporary large object registration table is set to tmp concatenated with the unique identifier of the target session of type UUID. In this way, the table can be identified as a temporary large object registration table by the fixed identifier tmp, and the target session corresponding to the table can be identified by the UUID value.
[0178] lob_id, which can be of UUID type and is used as an identifier for a temporary large object;
[0179] lob_type, which is the temporary large object type OID that indicates the large object type of this temporary large object.
[0180] blob_val, which is a large object of the BLOB type. When the temporary large object is of the BLOB type, its reference relationship is filled in this column, and the other two columns are set to NULL.
[0181] clob_val, which is a large object of the CLOB type. When the temporary large object is of the CLOB type, its reference relationship is filled in this column, and the other two columns are set to NULL.
[0182] nclob_val, which is a large object of NCLOB type. When the temporary large object is of NCLOB type, its reference relationship is filled in this column, and the other two columns are set to NULL.
[0183] An example of the actual use of the temporary large object registration table is as follows Fig. 9 As shown:
[0184] The first line indicates that the unique identifier of the temporary large object registration table itself is tmp_<random uuid> , where random uuid can represent the UUID value corresponding to the target session;
[0185] The second line indicates the column name corresponding to each column in the temporary large object registration table.
[0186] The third row indicates the first temporary large object in the target session that is used as a temporary storage target. Its oid is tmp_lob1 uuid, and its corresponding large object type is clob type oid. Therefore, its reference relationship or data is filled in the clob_val column, and the other two columns are set to NULL.
[0187] Similarly, the fourth to sixth rows are all the contents recorded in the temporary large object registration table as temporary storage targets. The specific values of UUID are not reflected, and they are distinguished by different identifiers. Those skilled in the art can set the design rules corresponding to the specific values of different columns according to the actual situation.
[0188] pass Figure 8 and Fig. 9 The temporary large object registration table shown in the figure can be combined with the temporary large object storage table to clearly distinguish and record the data of all temporary large objects in different sessions in the database, thereby helping the database to quickly obtain the data information of the corresponding temporary large objects. And after the target session ends, its corresponding data table can be directly deleted, thereby realizing the rapid cleanup of temporary large objects and saving database space resources.
[0189] The flow chart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical thinking provided by the present embodiment method, additional changes may be made to the above method.
[0190] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0191] This embodiment also provides a computer program product 10 , a computer readable storage medium 20 , and a computer device 30 . Fig.10 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Fig.11 is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention, Fig.12 is a schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned methods for storing temporary large objects in a database when executed by a processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11, which implements the steps of any of the above-mentioned methods for storing temporary large objects in a database when executed by a processor 32. The computer device 30 may include a memory 31, a processor 32, and the computer program 11 stored in the memory 31 and running on the processor 32.
[0192] The computer program 11 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages and process programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider via the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA) may execute computer-readable program instructions by utilizing the state information of the computer-readable program instructions to personalize the electronic circuit.
[0193] For the purposes of the description of the present embodiment, the computer program product 10 is a related product that includes the computer program 11. For the purposes of the description of the present embodiment, the computer readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which may be any device that can contain, store, communicate, propagate or transmit the program 11 for use with or in conjunction with an instruction execution system, device or apparatus. More specific examples (a non-exhaustive list) of the computer readable storage medium 20 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.
[0194] The computer device 30 may be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, the computer device 30 may be a cloud computing node. The computer device 30 may be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module may include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 30 may be implemented in a distributed cloud computing environment where remote processing devices linked via a communication network perform tasks. In a distributed cloud computing environment, program modules may be located on a local or remote computing system storage medium including a storage device.
[0195] The computer device 30 may include a processor 32 adapted to execute stored instructions, and a memory 31 providing temporary storage space for the operation of the instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 31 may include a random access memory (RAM), a read-only memory, a flash memory, or any other suitable storage system.
[0196] The computer device 30 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows data to be input and output with external devices that may be connected to the computer device. The network adapter / interface may provide communication between the computer device and a network, which is typically shown as a communication network.
[0197] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A method for storing temporary large objects in a database, comprising: determining a target session in the database; Acquire a temporary large object to be stored in the target session as a temporary storage target; Generating a temporary large object registration table according to the target session, wherein the temporary large object registration table is used to record reference information of the temporary storage target; A temporary large object storage table is established, where the temporary large object storage table is used to record data of the temporary storage target and corresponds to the temporary large object registration table.
2. The storage method of temporary large objects in a database according to claim 1, wherein: The step of establishing a temporary large object storage table further includes: Setting a life cycle for the temporary storage target, where the life cycle of the temporary storage target is determined by the life cycle of the variable bound to the temporary storage target; When the life cycle is reached, the temporary storage target is deleted.
3. The storage method of temporary large objects in a database according to claim 1, wherein: The step of establishing a temporary large object storage table further includes: When the target session ends, the temporary large object storage table is deleted.
4. The storage method of temporary large objects in a database according to claim 1, wherein: The step of generating a temporary large object registration table according to the target session comprises: Generate a table name of the temporary large object registration table according to the target session, wherein the table name is used to search for all temporary large objects corresponding to the target session; The temporary large object registration table is created according to the table name, and the temporary storage target is filled into the temporary large object registration table.
5. The storage method of temporary large objects in a database according to claim 4, wherein: The temporary large object registration table includes a temporary large object identifier, a temporary large object type, and at least one temporary large object column; The step of filling the temporary storage target into the temporary large object registration table comprises: Generate a unique identifier according to the temporary storage target, and use the unique identifier as the identifier; Determine the temporary large object type of the temporary storage target and generate a corresponding type identifier; Fill the type identifier into the temporary large object type column of the data row where the temporary storage target is located; The reference information of the temporary storage target is filled into the corresponding temporary large object column according to the type identifier, wherein the reference information is the corresponding relationship between the temporary storage target and the temporary large object storage table.
6. The storage method of temporary large objects in a database according to claim 5, wherein: The step of establishing a temporary large object storage table comprises: Establishing the same number of temporary large object storage tables according to the number of temporary large object columns, wherein the temporary large object storage tables are used to store description information and data of storage slices corresponding to the temporary large objects; The data of the temporary storage target is divided into multiple storage slices according to a preset splitting rule, and stored in the temporary large object storage table.
7. The storage method of temporary large objects in a database according to claim 4, wherein: The step of generating the table name of the temporary large object registration table according to the target session comprises: Generate a unique identifier according to the target session, where the unique identifier is of UUID type; A fixed identifier is added to the unique identifier according to a preset rule, thereby obtaining the table name of the temporary large object registration table.
8. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for storing temporary large objects in a database according to any one of claims 1 to 7 are implemented.
9. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method for storing temporary large objects in a database according to any one of claims 1 to 7.
10. A computer device comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, wherein the processor implements the steps of the method for storing temporary large objects in a database according to any one of claims 1 to 7 when executing the machine executable program.
