CN115617844A - Database query method and device - Google Patents

Database query method and device Download PDF

Info

Publication number
CN115617844A
CN115617844A CN202211179660.1A CN202211179660A CN115617844A CN 115617844 A CN115617844 A CN 115617844A CN 202211179660 A CN202211179660 A CN 202211179660A CN 115617844 A CN115617844 A CN 115617844A
Authority
CN
China
Prior art keywords
field
index
target
determining
record
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211179660.1A
Other languages
Chinese (zh)
Inventor
刘博�
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
CCB Finetech Co Ltd
Original Assignee
China Construction Bank Corp
CCB Finetech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN202211179660.1A priority Critical patent/CN115617844A/en
Publication of CN115617844A publication Critical patent/CN115617844A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a database query method and a database query device, and relates to the technical field of database operation. One embodiment of the method comprises: receiving a query statement, wherein the query statement comprises: a condition field and a condition value; generating a target index field corresponding to the query statement according to the condition field and the condition value; determining a target index sub-table corresponding to the target index field, and determining a target record identifier corresponding to the target index field from the target index sub-table; determining a target content sublist corresponding to the target record identifier, and determining a target record corresponding to the target record identifier from the target content sublist; and determining a query result corresponding to the query statement according to the target record. The embodiment can improve the query efficiency of the data table.

Description

Database query method and device
Technical Field
The invention belongs to the technical field of database operation, and particularly relates to a database query method and a database query device.
Background
Relational databases refer to database systems that employ a relational data model. Relational databases store data in a manner similar to tables, with each table of data referred to as a table. Relational databases, the most common component of persistence, have been driven into the construction of various information systems. In the process of using the database, the size of the data table is larger and larger along with the increase of the data amount, and after the size of the data table reaches a certain magnitude, the query for the data table becomes very slow.
Disclosure of Invention
In view of this, embodiments of the present invention provide a database query method and apparatus, which can improve query efficiency for a data table after a scale of the data table reaches a certain magnitude.
In a first aspect, an embodiment of the present invention provides a database query method, including:
receiving a query statement, wherein the query statement comprises: a condition field and a condition value;
generating a target index field corresponding to the query statement according to the condition field and the condition value;
determining a target index sub-table corresponding to the target index field, and determining a target record identifier corresponding to the target index field from the target index sub-table;
determining a target content sublist corresponding to the target record identifier, and determining a target record corresponding to the target record identifier from the target content sublist;
and determining a query result corresponding to the query statement according to the target record.
Optionally, the generating a target index field corresponding to the query statement according to the condition field and the condition value includes:
determining a field identifier corresponding to the condition field;
and combining the field identification and the condition value to generate a target index field corresponding to the query statement.
Optionally, the determining a target index table corresponding to the target index field includes:
determining a content table corresponding to the query statement;
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
and determining the target index sub-table from the plurality of index sub-tables according to the hash value of the target index field.
Optionally, the determining the target content sublist corresponding to the target record identifier includes:
determining a content table corresponding to the query statement, wherein the content table is composed of a plurality of content sub-tables;
and determining the target content sublist from the plurality of content sublists according to the hash value of the target record identifier.
Optionally, the method further comprises:
determining a record to be inserted aiming at a content table, wherein the content table consists of a plurality of content sub-tables;
determining a record identifier corresponding to the record to be inserted;
determining a content sub-table corresponding to the record to be inserted from the plurality of content sub-tables according to the hash value of the record identifier corresponding to the record to be inserted;
and inserting the record to be inserted into the content sub-table corresponding to the record to be inserted.
Optionally, after determining the record to be inserted for the table of contents, the method further includes:
determining at least one table field in the table of contents;
for each table field, determining a field identifier corresponding to the table field and an insertion value of the table field in the record to be inserted; combining the field identification and the inserted value to generate an index field of the table field; determining a record identifier corresponding to the record to be inserted; and generating an index record of the table field according to the index field and the record identifier, and inserting the index record of the table field into an index table.
Optionally, the inserting the index record of the table field into an index table includes:
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
determining an index sub-table corresponding to the table field from the plurality of index sub-tables according to the hash value of the index field of the table field;
and inserting the index record of the table field into the index sub-table corresponding to the table field.
Optionally, the query statement includes: a plurality of condition fields and a condition value of each of the condition fields;
the determining the target record corresponding to the target record identifier from the target content sublist includes:
for each condition field, determining a target record corresponding to the condition field from a target content sublist corresponding to the condition field;
determining a query result corresponding to the query statement according to the target record, including:
determining a record intersection of the target records corresponding to the condition fields;
and determining the record intersection as a query result corresponding to the query statement.
In a second aspect, an embodiment of the present invention provides a database query apparatus, including:
a statement receiving module, configured to receive a query statement, where the query statement includes: a condition field and a condition value;
a field generating module, configured to generate a target index field corresponding to the query statement according to the condition field and the condition value;
the first determining module is used for determining a target index sublist corresponding to the target index field and determining a target record identifier corresponding to the target index field from the target index sublist;
the second determining module is used for determining a target content sublist corresponding to the target record identifier and determining a target record corresponding to the target record identifier from the target content sublist;
and the result determining module is used for determining the query result corresponding to the query statement according to the target record.
Optionally, the field generating module is specifically configured to:
determining a field identifier corresponding to the condition field;
and combining the field identification and the condition value to generate a target index field corresponding to the query statement.
Optionally, the first determining module is specifically configured to:
determining a content table corresponding to the query statement;
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
and determining the target index sub-table from the plurality of index sub-tables according to the hash value of the target index field.
Optionally, the second determining module is specifically configured to:
determining a content table corresponding to the query statement, wherein the content table is composed of a plurality of content sub-tables;
and determining the target content sublist from the plurality of content sublists according to the hash value of the target record identifier.
In a third aspect, an embodiment of the present invention provides an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any of the embodiments described above.
In a fourth aspect, an embodiment of the present invention provides a computer-readable medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method of any one of the above embodiments.
In a fifth aspect, an embodiment of the present invention provides a computer program product, which includes a computer program, and when the program is executed by a processor, the computer program implements the method described in any one of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: and setting an index table corresponding to the content table. The index table is used for storing the corresponding relation between the index field and the record identification. The index field is generated by the table field and the value of the table field in the content table. The table field is a field in the content table that can be used as a query condition. When the data amount in the content table and the index table is large, the content table is divided into a plurality of content sub-tables, and the index table is divided into a plurality of index sub-tables.
After receiving the query statement, firstly generating a target index field corresponding to the query statement, and determining a target record identifier corresponding to the query statement from a target index sublist. And determining the target record corresponding to the target record identifier from the target content sublist. And determining a query result corresponding to the query statement according to the target record. The method of the embodiment of the invention can avoid directly searching data in the content table storing a large amount of data by establishing the index table. Therefore, after the size of the data table reaches a certain magnitude, the query efficiency for the data table can be improved.
Furthermore, in the case where the amount of data in the table of contents is large and the table is split into a plurality of partial tables, if the condition field in the query statement is not a partial table field, it is generally necessary to query the result in the entire table of the table of contents. According to the scheme of the embodiment of the invention, the index identifier of the content table can be directly positioned by using the index table. Compared with full-table scanning, the method can significantly reduce the query time.
In addition, even if the condition field related to the query is changed, the corresponding index record is only required to be added or deleted in the index table, and other data in the content table and the index table are not influenced. Therefore, the scheme of the embodiment of the invention can flexibly support the query modes of various field combinations.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
fig. 1 is a schematic flowchart of a database query method according to a first embodiment of the present invention;
fig. 2 is a flowchart illustrating a data insertion method according to a second embodiment of the present invention;
fig. 3 is a schematic flowchart of a database query method according to a third embodiment of the present invention;
FIG. 4 is a schematic structural diagram of a database query device according to an embodiment of the present invention;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
According to the technical scheme, the data acquisition, storage, use, processing and the like meet the relevant regulations of national laws and regulations.
Fig. 1 is a schematic flowchart of a database query method according to a first embodiment of the present invention, as shown in fig. 1, the method includes:
step 101: receiving a query statement, wherein the query statement comprises: a condition field and a condition value.
The query statement is used for querying a result meeting the query condition from the content table. The condition field is a table field in the content table, and the condition value is a corresponding value of the condition field. The condition field and the condition value are used to determine the query condition. For example, if the table of contents is used to store student record information, the table of contents includes an age field, and the query statement is used to query student records with an age of 20, the condition field may be set as the student, and the condition value may be set as 20.
Under the condition that the query statement is an SQL statement, the condition field and the corresponding condition value can be extracted from the field after the keyword "where".
Step 102: and generating a target index field corresponding to the query statement according to the condition field and the condition value.
And generating a unique target index field according to the condition field and the condition value. The condition field and the condition value can also be uniquely determined by the target index field.
There are many ways to generate the index field based on the condition field and the condition value. For example, the condition field and the condition value may be directly combined into the index field. The target index field corresponding to the query statement may also be generated by: determining a field identifier corresponding to the condition field; and combining the field identification and the condition value to generate a target index field corresponding to the query statement.
Different field identifications are set for different condition fields, and the condition fields and the field identifications are in one-to-one correspondence. The field identification is short, so that comparison and search are convenient.
Step 103: and determining a target index sublist corresponding to the target index field, and determining a target record identifier corresponding to the target index field from the target index sublist.
And setting an index table corresponding to the content table. The index table is used for storing the corresponding relation between the index field and the record identification. The record identification and the record in the content table are in one-to-one correspondence. By means of the record identification, a unique record can be determined in the table of contents. The index field is generated by the table field and the value of the table field in the content table. The table field is a field in the content table that can be used as a query condition. The stored contents in the index table include: index field, record identification. The stored contents in the table of contents include: recording identification and specific content of the record.
Specifically, table fields in the content table that can be used as query conditions are determined. And aiming at each record in the content table, respectively generating an index field corresponding to each table field, and acquiring a record identifier of the record. And combining the record identifications of the index fields to generate index records corresponding to the index fields, and inserting the index records corresponding to the index fields into an index table.
The index field in the index table corresponds to all the query conditions, and the index table also contains corresponding record identifications. The index field is listed as a combination of query type and query specific information. The content table stores record identification and specific data content.
For example, the table of contents is used to store student record information. The table fields in the table of contents that can be used as query conditions are: school size and age. The field identification corresponding to the school number is xh, and the field identification corresponding to the age is age. For one record in the table of contents, the record is identified as num1, with a school number of 001 and an age of 21. Then, for the record, the index field corresponding to the academic number field is: xh001, index record corresponding to the academic number is (xh 001, num 1). The index field corresponding to the age field is: nl21, the index record corresponding to the age field is (nl 21, num 1). And storing the two index records in an index table.
In the case where the data size of the table of contents is large and the condition field in the query statement is not the branch table field of the table of contents, the result of the full table query in the table of contents is usually required. By applying the scheme of the embodiment of the invention, after the query statement is received, the index field corresponding to the query statement can be determined, and the corresponding record identifier is positioned from the index table by utilizing the index field; and the record identification is utilized to quickly locate the relevant record from the content table.
When the data amount in both the content table and the index table is large, the content table is divided into a plurality of content sub-tables, and the index table is divided into a plurality of index sub-tables. The table of contents may be sorted and tabulated according to the record identifier. And performing library and table division on the index table according to the index field.
In an embodiment of the present invention, determining a target index table corresponding to a target index field includes: determining a content table corresponding to the query statement; determining an index table corresponding to the content table, wherein the index table consists of a plurality of index sub-tables; and determining the target index sublist from the index sublists according to the hash value of the target index field.
When the data volume in the index table is large, the index table can be sorted according to the hash value of the index field to obtain a plurality of index sorting tables, so that the data volume in each index sorting table is reduced. After receiving the query statement, determining a target index field corresponding to the query statement, and determining a target index sublist from the index sublists according to the hash value of the target index field.
Step 104: and determining a target content sublist corresponding to the target record identifier, and determining a target record corresponding to the target record identifier from the target content sublist.
When the data amount in the content table is large, the content table can be sorted according to the hash value of the record identifier to obtain a plurality of content sorting tables, so that the data amount in each content sorting table is reduced. After receiving the query statement, determining a target record identifier corresponding to the query statement by using the index table, and determining a target content sublist from the plurality of content sublists according to the hash value of the target record identifier. And the query efficiency can be further improved by determining the target record from the small content sub-table according to the data volume.
Step 105: and determining a query result corresponding to the query statement according to the target record.
In the case where only one condition field is included in the query statement, the target record may be directly used as the query result of the query statement. Under the condition that the query statement comprises a plurality of condition fields, determining a target record corresponding to each condition field; determining a combination mode of the target records corresponding to each condition field according to the query statement; and combining the target records corresponding to the condition fields in the combination mode to obtain a query result corresponding to the query statement. The combination mode can include: intersect, merge, etc.
In the embodiment of the invention, after receiving the query statement, a target index field corresponding to the query statement is generated firstly, and a target record identifier corresponding to the query statement is determined from a target index sublist. And determining the target record corresponding to the target record identifier from the target content sublist. And determining a query result corresponding to the query statement according to the target record. The method of the embodiment of the invention can avoid directly searching data in the content table storing a large amount of data by establishing the index table. Therefore, after the size of the data table reaches a certain magnitude, the query efficiency for the data table can be improved.
Furthermore, in the case where the amount of data in the table of contents is large and the table is split into a plurality of partial tables, if the condition field in the query statement is not a partial table field, it is generally necessary to query the result in the entire table of the table of contents. According to the scheme of the embodiment of the invention, the index identifier of the content table can be directly positioned by using the index table. Compared with full-table scanning, the method can significantly reduce the query time.
Fig. 2 is a schematic flowchart of a data insertion method according to a second embodiment of the present invention, as shown in fig. 2, the method includes:
step 201: and determining a record to be inserted aiming at a content table, wherein the content table is composed of a plurality of content sub-tables.
Step 202: and determining the record identifier corresponding to the record to be inserted.
Step 203: and determining the sub-table of the content corresponding to the record to be inserted from the plurality of sub-tables of the content according to the hash value of the record identifier corresponding to the record to be inserted.
The content table is divided into a plurality of content sub-tables according to the hash value of the record identifier. And when data is inserted, determining the content sub-table corresponding to the record to be inserted from the plurality of content sub-tables according to the hash value of the record identifier corresponding to the record to be inserted.
Step 204: and inserting the record to be inserted into the content sub-table corresponding to the record to be inserted.
Step 205: at least one table field in the table of contents is determined.
Table fields are fields that may be involved in a query statement. Different field identifications can be set for different table fields, and the table fields and the field identifications are in one-to-one correspondence. The field identification is short, so that comparison and search are convenient.
Step 206: determining field identifications corresponding to the table fields and insertion values of the table fields in records to be inserted aiming at the table fields; combining the field identification and the inserted value to generate the index field of the table field.
There are many ways to generate table fields. For example, the table field and the inserted value may be directly combined into the index field. The target index field corresponding to the query statement may also be generated by: determining a field identifier corresponding to the table field; combining the field identification and the inserted value to generate the index field of the table field.
Step 207: determining a record identifier corresponding to a record to be inserted; and generating an index record of the table field according to the index field and the record identifier, and inserting the index record of the table field into the index table.
For example, the table of contents is used to store student record information. The table fields in the table of contents that can be used as query conditions are: school, age and specialty. The field identification corresponding to the school number is xh, the field identification corresponding to the age is nl, and the field identification corresponding to the specialty is zy. To insert into the record, the record is labeled num2, school number 002, age 23, professional computer. Then, for the record, the index field corresponding to the academic number field is: the index corresponding to xh002, academic number is (xh 002, num 2). The index field corresponding to the age field is: nl23, the index record corresponding to the age field is (nl 23, num 2). The index fields corresponding to the professional fields are as follows: zycomputer, the index record corresponding to the age field is (zycomputer, num 2). And respectively calculating the hash values of xh002, nl23 and zycomputer, determining the index sub-tables corresponding to the three index records according to the obtained hash values, and storing the three index records in the index tables.
The embodiment of the invention provides a data record inserting method. And generating at least one index record corresponding to a data record while inserting the data record into the content table, and inserting the index record into the index table corresponding to the content table. When the query statement is received, the index table can be utilized to improve the execution efficiency of the query statement.
In one embodiment of the present invention, inserting the index record of the table field into the index table comprises: determining an index table corresponding to the content table, wherein the index table consists of a plurality of index sub-tables; determining an index sub-table corresponding to the table field from the plurality of index sub-tables according to the hash value of the index field of the table field; and inserting the index record of the table field into the index sub-table corresponding to the table field.
When the data volume in the index table is large, the index table is divided into a plurality of index sub-tables according to the hash value of the index field. When data is inserted, at least one index field corresponding to a record to be inserted is determined, and an index sublist corresponding to each index field is determined from a plurality of index sublists according to the hash value of each index field.
To facilitate understanding of the solution of the embodiment of the present invention, the following description is made by taking an example of a user ordering system. The order system relates to three inquiry modes of a mobile phone number, a user name and an identity card number. Presentation and paging are performed in reverse order of creation time. Before using the sublibrary and sublibrary, the table structure is (order number, user name, mobile phone number, identity card number, other specific data, order creation time).
By applying the scheme in the embodiment of the invention, the index table and the content table are established. The table structure of the index table is (index field, order number, order creation time). The table structure of the table of contents is: (order number, data integrity content). The order number is used as a unique identifier of the order, and the order number is equivalent to the record identifier in the embodiment of the invention.
The corresponding field identifications of the user name, the mobile phone number and the identity card number are respectively as follows: un, mb and cc. The field identification can be modified according to the requirement, and can be distinguished. If an order with order number 12345 has a cell phone number 13123456789, a user name username, an identity card number 123456789012345678, and a creation date 1970-01-01, then three index records are added to the index library, which are (mb 13123456789, 12345, 1970-01-01), (unusername, 12345, 1970-01-01), (cc 123456789012345678, 12345, 1970-01-01). And respectively recording the three index records into corresponding index sub-tables according to the sub-table rules.
In the table of contents, the content is recorded as (12345, order complete information). And creating 256 content sublists, performing sublist on the 256 remainders by using the order number, determining the content sublist 57 as the content sublist corresponding to the current data record, and storing the current data record in the content sublist 57.
When a specific order is queried, taking querying all orders of a user with an identity card number of 123456789012345678 as an example, the process is as follows:
and determining that the field identifier corresponding to the ID card field is cc, and the condition value is 123456789012345678, and then the index field is 'cc 123456789012345678'.
And calculating the index sublist according to the index field, and if 256 index sublists exist, calculating the sublist expression in a mode of "- { str }. Hashcode ()% 256", and determining the target index sublist to be the index sublist 129.
The corresponding record is looked up in the index table 129, and the index record of (cc 123456789012345678, 12345, 1970-01-01) is looked up.
And according to the order number of 12345, determining the target content sublist to be the content sublist 57, and searching for a specific record in the content sublist 57 and returning.
And for example, querying the user order with the mobile phone number 13123456789, which is similar to the querying process. The difference is that the index field corresponding to the query statement is "mb13123456789", and then the target index sub-table is determined to be the index sub-table 158, and the order number is 12345 in the index sub-table 158. The subsequent query steps and query results are the same as the query process described above.
The scheme of the embodiment of the invention expands the concept of 'index' in the traditional database, and realizes the change of various index fields in the sub-database and sub-table by independently storing the index. The index table increases the query speed by using a mode similar to the key value database idea.
In addition, a plurality of query modes can be supported, and other query fields can be flexibly added to the index table at any time later without influencing the existing data. And the index performance of the relational database can be fully utilized, and the related problems caused by a large table can be avoided.
In addition, other components are not required to be introduced, and the problem that multiple data sources are inconsistent in data is avoided. The index library and the content library can be respectively constructed, and particularly for the content library, a MongoDB key value database and other key value databases can be selected subsequently to further enhance the performance of the database.
Fig. 3 is a schematic flowchart of a database query method according to a third embodiment of the present invention, as shown in fig. 3, the method includes:
step 301: receiving a query statement, the query statement comprising: a plurality of condition fields and condition values for each condition field.
Step 302: and generating a target index field corresponding to each condition field according to each condition field and the corresponding condition value thereof.
The target index field includes at least one index field.
Step 303: and determining a target index sublist corresponding to each target index field, and determining a target record identifier corresponding to each condition field from each target index sublist.
The target record identification comprises at least one record identification.
Step 304: and aiming at each condition field, determining a target content sublist corresponding to the condition field, and determining a target record corresponding to the condition field from the target content sublist.
The target record includes at least one data record.
Step 305: and determining the record intersection of the target records corresponding to each condition field.
Step 306: and determining the record intersection as a query result corresponding to the query statement.
Under the condition that the query statement comprises a plurality of condition fields, the scheme of the embodiment of the invention can also accurately and quickly determine the query result. Specifically, determining target records corresponding to each condition field; determining a combination mode of the target records corresponding to each condition field according to the query statement; and combining the target records corresponding to the condition fields in the combination mode to obtain a query result corresponding to the query statement. The combination mode can include: intersect, merge, etc.
For example, the query is professional student information of computer and age 23. The condition fields are professional and age, respectively. Using steps 302-304, a first target record of computer professional and a second target record of age 23 are obtained, respectively. Determining the record intersection of the first target record and the second target record, and taking the record intersection as a query result.
As another example, the query specialty is computer, or student information of age 23. The condition fields are professional and age, respectively. Using steps 302-304, a first target record of computer professional and a second target record of age 23 are obtained, respectively. Determining a record union of the first target record and the second target record, and taking the record union as a query result.
Fig. 4 is a schematic structural diagram of a database querying device according to an embodiment of the present invention, as shown in fig. 4, the database querying device includes:
a statement receiving module 401, configured to receive a query statement, where the query statement includes: a condition field and a condition value;
a field generating module 402, configured to generate a target index field corresponding to the query statement according to the condition field and the condition value;
a first determining module 403, configured to determine a target index sub-table corresponding to the target index field, and determine a target record identifier corresponding to the target index field from the target index sub-table;
a second determining module 404, configured to determine a target content sublist corresponding to the target record identifier, and determine a target record corresponding to the target record identifier from the target content sublist;
and a result determining module 405, configured to determine, according to the target record, a query result corresponding to the query statement.
Optionally, the field generating module 402 is specifically configured to:
determining a field identifier corresponding to the condition field;
and combining the field identification and the condition value to generate a target index field corresponding to the query statement.
Optionally, the first determining module 403 is specifically configured to:
determining a content table corresponding to the query statement;
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
and determining the target index sub-table from the plurality of index sub-tables according to the hash value of the target index field.
Optionally, the second determining module 404 is specifically configured to:
determining a content table corresponding to the query statement, wherein the content table is composed of a plurality of content sub-tables;
and determining the target content sublist from the plurality of content sublists according to the hash value of the target record identifier.
Optionally, the apparatus further comprises:
a first insertion module 406, configured to determine a record to be inserted for a content table, where the content table is composed of a plurality of content sub-tables;
determining a record identifier corresponding to the record to be inserted;
determining a content sub-table corresponding to the record to be inserted from the plurality of content sub-tables according to the hash value of the record identifier corresponding to the record to be inserted;
and inserting the record to be inserted into the content sublist corresponding to the record to be inserted.
Optionally, the apparatus further comprises:
a second insertion module 407, configured to determine at least one table field in the content table;
determining a field identifier corresponding to each table field and an insertion value of the table field in the record to be inserted for each table field; combining the field identification and the inserted value to generate an index field of the table field; determining a record identifier corresponding to the record to be inserted; and generating an index record of the table field according to the index field and the record identifier, and inserting the index record of the table field into an index table.
Optionally, the second insertion module 407 is specifically configured to:
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
determining an index sub-table corresponding to the table field from the plurality of index sub-tables according to the hash value of the index field of the table field;
and inserting the index record of the table field into the index sub-table corresponding to the table field.
Optionally, the query statement includes: a plurality of condition fields and a condition value of each of the condition fields;
the second determining module 404 is specifically configured to:
for each condition field, determining a target record corresponding to the condition field from a target content sublist corresponding to the condition field;
the result determination module 405 is specifically configured to:
determining record intersection of target records corresponding to the condition fields;
and determining the record intersection as a query result corresponding to the query statement.
An embodiment of the present invention provides an electronic device, including:
one or more processors;
a storage device to store one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method of any of the embodiments described above.
Embodiments of the present invention provide a computer program product, including a computer program, which, when executed by a processor, implements an enterprise risk assessment method in embodiments of the present invention.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing embodiments of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the use range of the embodiment of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU) 501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted on the storage section 508 as necessary.
In particular, according to embodiments of the present disclosure, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: the device comprises a statement receiving module, a field generating module, a first determining module, a second determining module and a result determining module. Where the names of these modules do not in some cases constitute a limitation on the module itself, for example, the statement receiving module may also be described as a "module that receives a query statement".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not assembled into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
receiving a query statement, wherein the query statement comprises: a condition field and a condition value;
generating a target index field corresponding to the query statement according to the condition field and the condition value;
determining a target index sub-table corresponding to the target index field, and determining a target record identifier corresponding to the target index field from the target index sub-table;
determining a target content sublist corresponding to the target record identifier, and determining a target record corresponding to the target record identifier from the target content sublist;
and determining a query result corresponding to the query statement according to the target record.
According to the technical scheme of the embodiment of the invention, after the query statement is received, the target index field corresponding to the query statement is generated firstly, and the target record identification corresponding to the query statement is determined from the target index sublist. And determining the target record corresponding to the target record identifier from the target content sublist. And determining a query result corresponding to the query statement according to the target record. The method of the embodiment of the invention can avoid directly searching data in the content table storing a large amount of data by establishing the index table. Therefore, after the size of the data table reaches a certain magnitude, the query efficiency for the data table can be improved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (15)

1. A database query method, comprising:
receiving a query statement, wherein the query statement comprises: a condition field and a condition value;
generating a target index field corresponding to the query statement according to the condition field and the condition value;
determining a target index sub-table corresponding to the target index field, and determining a target record identifier corresponding to the target index field from the target index sub-table;
determining a target content sublist corresponding to the target record identifier, and determining a target record corresponding to the target record identifier from the target content sublist;
and determining a query result corresponding to the query statement according to the target record.
2. The method of claim 1, wherein the generating a target index field corresponding to the query statement according to the condition field and the condition value comprises:
determining a field identifier corresponding to the condition field;
and combining the field identification and the condition value to generate a target index field corresponding to the query statement.
3. The method of claim 1, wherein the determining the target index table corresponding to the target index field comprises:
determining a content table corresponding to the query statement;
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
and determining the target index sublist from the index sublists according to the hash value of the target index field.
4. The method of claim 1, wherein the determining the target content sublist corresponding to the target record identifier comprises:
determining a content table corresponding to the query statement, wherein the content table is composed of a plurality of content sub-tables;
and determining the target content sublist from the plurality of content sublists according to the hash value of the target record identifier.
5. The method of claim 1, further comprising:
determining a record to be inserted aiming at a content table, wherein the content table is composed of a plurality of content sub-tables;
determining a record identifier corresponding to the record to be inserted;
determining a content sub-table corresponding to the record to be inserted from the plurality of content sub-tables according to the hash value of the record identifier corresponding to the record to be inserted;
and inserting the record to be inserted into the content sub-table corresponding to the record to be inserted.
6. The method of claim 5, wherein after determining the record to be inserted for the table of contents, further comprising:
determining at least one table field in the table of contents;
for each table field, determining a field identifier corresponding to the table field and an insertion value of the table field in the record to be inserted; combining the field identification and the inserted value to generate an index field of the table field; determining a record identifier corresponding to the record to be inserted; and generating an index record of the table field according to the index field and the record identifier, and inserting the index record of the table field into an index table.
7. The method of claim 6, wherein inserting the index record of the table field into an index table comprises:
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
determining an index sub-table corresponding to the table field from the plurality of index sub-tables according to the hash value of the index field of the table field;
and inserting the index record of the table field into the index sub-table corresponding to the table field.
8. The method of claim 1, wherein the query statement comprises: a plurality of condition fields and a condition value of each of the condition fields;
the determining the target record corresponding to the target record identifier from the target content sublist includes:
for each condition field, determining a target record corresponding to the condition field from a target content sublist corresponding to the condition field;
determining a query result corresponding to the query statement according to the target record, including:
determining record intersection of target records corresponding to the condition fields;
and determining the record intersection as a query result corresponding to the query statement.
9. A database query device, comprising:
a statement receiving module, configured to receive a query statement, where the query statement includes: a condition field and a condition value;
a field generating module, configured to generate a target index field corresponding to the query statement according to the condition field and the condition value;
the first determining module is used for determining a target index sublist corresponding to the target index field and determining a target record identifier corresponding to the target index field from the target index sublist;
the second determining module is used for determining a target content sublist corresponding to the target record identifier and determining a target record corresponding to the target record identifier from the target content sublist;
and the result determining module is used for determining the query result corresponding to the query statement according to the target record.
10. The apparatus of claim 9, wherein the field generation module is specifically configured to:
determining a field identifier corresponding to the condition field;
and combining the field identification and the condition value to generate a target index field corresponding to the query statement.
11. The apparatus of claim 9, wherein the first determining module is specifically configured to:
determining a content table corresponding to the query statement;
determining an index table corresponding to the content table, wherein the index table is composed of a plurality of index sub-tables;
and determining the target index sub-table from the plurality of index sub-tables according to the hash value of the target index field.
12. The apparatus of claim 9, wherein the second determining module is specifically configured to:
determining a content table corresponding to the query statement, wherein the content table is composed of a plurality of content sub-tables;
and determining the target content sublist from the plurality of content sublists according to the hash value of the target record identifier.
13. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-8.
14. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-8.
15. A computer program product comprising a computer program, characterized in that the computer program realizes the method according to any of claims 1-8 when executed by a processor.
CN202211179660.1A 2022-09-27 2022-09-27 Database query method and device Pending CN115617844A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211179660.1A CN115617844A (en) 2022-09-27 2022-09-27 Database query method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211179660.1A CN115617844A (en) 2022-09-27 2022-09-27 Database query method and device

Publications (1)

Publication Number Publication Date
CN115617844A true CN115617844A (en) 2023-01-17

Family

ID=84859714

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211179660.1A Pending CN115617844A (en) 2022-09-27 2022-09-27 Database query method and device

Country Status (1)

Country Link
CN (1) CN115617844A (en)

Similar Documents

Publication Publication Date Title
CN111522816B (en) Data processing method, device, terminal and medium based on database engine
CN111708804B (en) Data processing method, device, equipment and medium
CN108932313B (en) Data processing method and device, electronic equipment and storage medium
EP2889788A1 (en) Accessing information content in a database platform using metadata
CN111813804A (en) Data query method and device, electronic equipment and storage medium
US10990573B2 (en) Fast index creation system for cloud big data database
CN112685446B (en) Complex SQL query method, device, processor and storage medium through elastic search database
CN115576905A (en) Archive file management method and device, electronic equipment and storage medium
CN112395307A (en) Statement execution method, statement execution device, server and storage medium
CN108694172B (en) Information output method and device
CN111858581B (en) Paging query method and device, storage medium and electronic equipment
US20190340179A1 (en) Result set output criteria
CN115617844A (en) Database query method and device
CN112835905B (en) Array type column indexing method, device, equipment and storage medium
CN112905627B (en) Data processing method, data processing device, computer equipment and storage medium
CN111324624B (en) Merge intro function compatible method, equipment and storage medium of database component
CN116263770A (en) Method, device, terminal equipment and medium for storing business data based on database
CN110609926A (en) Data tag storage management method and device
CN110109919B (en) Method and device for determining logic information
CN111737282B (en) Method and system for organizing database query conditions by receiving parameters at server
CN115599976B (en) User grouping method, device, electronic equipment and storage medium
CN115357604B (en) Data query method and device
CN117130937A (en) Test case processing method, device, electronic equipment and storage medium
CN115422367A (en) User data mapping construction method and system, electronic equipment and storage medium
CN115422238A (en) Statement verification method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination