This application claims the benefit of Korean Patent Application No. 10-2014-0079114, filed on Jun. 26, 2014, in the Korean Intellectual Property Office, the disclosure of which is incorporated herein in its entirety by reference.
1. Field
One or more embodiments of the present invention relate to a method of moving data between tables in a database.
2. Description of the Related Art
It is inconvenient to use several structural query language (SQL) statements to move data between tables. In addition, a source table is searched twice, and even at this time, data that is inserted may be inconsistent with data that is deleted. KR 2010-0080817 discloses a technique of controlling access of database.
One or more embodiments of the present invention include a method of moving data from a memory to a disk. In addition, one or more embodiments of the present invention include a method of moving data between tables.
Additional aspects will be set forth in part in the description which follows and, in part, will be apparent from the description, or may be learned by practice of the presented embodiments.
According to one or more embodiments of the present invention, there is provided a database that implements a method of moving data from a memory to a disk. The method, which is performed by a computer and uses a single structural query language (SQL) statement, includes: searching for and reading a record that satisfies a certain condition in the memory; when the record that satisfies the certain condition is read, generating a destination record by using data within a column list in which the record read in the memory is comprised; and receiving a new page from the disk and inserting the destination record into the new page, wherein the searching for and reading, the generating, and the receiving and inserting are repeatedly performed in the database until the record that satisfies the certain condition is no longer found in the memory in the searching for and reading, and if the record that satisfies the certain condition is no longer found, all records that are searched for in the memory and satisfy the certain condition are deleted.
According to one or more embodiments of the present invention, there is provided a method, performed by a computer, of moving data in a certain partition by performing a single operation in a database, the method including: searching for a record that satisfies a condition in a source partition; generating a destination record by using data in a column list of the source partition where the record is searched for; and inserting the generated destination record into a new page by receiving the new page from a destination partition; wherein the searching for, the generating, and the inserting are sequentially and repeatedly performed, and if the record that satisfies the condition is no longer found in the searching for, all the records, which are searched for while the searching for, the generating, and the inserting are sequentially and repeatedly performed, are deleted.
These and/or other aspects will become apparent and more readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings in which:
Also, data are inconsistent as shown in
As shown in
In a LIMIT statement (S310) shown in
Each operation described in
MOVE INTO destination table (column_list) FROM source table (column_list) WHERE condition
MOVE INTO Disk FROM Memory WHERE condition
In the first SQL statement example, “column_list” indicated in “destination table (column_list)” is a list of columns included in a destination table. “column_list” indicated in “source table (column_list)” is a list of columns included in a source table and may include a list of expressions. In this case, the expressions may include at least one of four fundamental arithmetic operations, host variables, sub-queries, conversion functions, and constants.
Referring to the second SQL statement example, a record satisfying a certain condition is searched for and read in a memory in operation S410. When a record, which satisfies a “condition” indicated after the WHERE statement, is read, a destination record is generated by using data in a column list in which the record read in the memory is included, in operation S420.
Then, a new page is assigned by a disk, and the generated destination record is inserted into the new page, in operation S430.
Operations S410 through S430 are repeatedly performed until it is determined that the record that satisfies the certain condition is no longer found in the memory in operation S440.
If the record that satisfies the “condition” indicated after the WHERE statement is no longer found, all records found in the memory and satisfying the “condition” indicated after the WHERE statement are deleted, in operation S450.
In a database, each column values of I1 and I2 of the rows the second table 510, which satisfy the condition of T2.I2=4, are inserted into rows of two columns I1 and I2 of the first table 520 in operation S510, and then are deleted from the second table 510, in operation S520.
Hints 710 are hints regarding a FROM clause 720 and are the same as hints used in a SELECT statement.
A source_tbl_name 730 and a target_tbl_name 740 respectively denote a source table and a destination table with regard to movement of data.
A column_commalist 741 of
An expression_commalist 750 of
A where_clause 760 of
A limit_clause 770 of
In the source table of a database, a record that satisfies a condition is searched for and read, in operation S1210. When the record that satisfies the condition is read, a destination record is generated by using data within a column list of the source table, which is to be moved, in operation S1220.
The destination record is inserted into the destination table in operation S1230. Then, in operation S1240, operation S1210, operation S1220, and operation S1230 are repeatedly performed in the database until it is determined that the record that satisfies the condition is no longer found in the source table in operation S1210.
If the record that satisfies the condition is no longer found, all records that satisfy the condition and are found in the source table are deleted, in operation S1250.
As described above, according to the one or more of the above embodiments of the present invention, data may be moved between tables by using a single SQL statement, and since the data may be moved between tables after searching a source table only once, search costs may be reduced.
Also, when the data is moved between tables, moving data input into a table may be inconsistent with data deleted from the table. However, one or more embodiments of the present invention include solutions to the above-described problem, and thus, the data may be accurately moved.
The invention can also be embodied as computer readable codes on a computer readable recording medium. The computer readable recording medium is any data storage device that can store programs or data which can be thereafter read by a computer system.
Examples of the computer readable recording medium include read-only memory (ROM), random-access memory (RAM), CD-ROMs, magnetic tapes, hard disks, floppy disks, flash memory, optical data storage devices, and so on. The computer readable recording medium can also be distributed over network coupled computer systems so that the computer readable code is stored and executed in a distributive manner.
It should be understood that the exemplary embodiments described therein should be considered in a descriptive sense only and not for purposes of limitation. Descriptions of features or aspects within each embodiment should typically be considered as available for other similar features or aspects in other embodiments.
While one or more embodiments of the present invention have been described with reference to the figures, it will be understood by those of ordinary skill in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present invention as defined by the following claims.
Number | Date | Country | Kind |
---|---|---|---|
10-2014-0079114 | Jun 2014 | KR | national |