This topic describes the requirements and suggestions on writing DML statements in OceanBase Database.
You must specify the name of the column to be inserted in an
INSERTstatement. Do not write the statement in theINSERT VALUES(...)format.Do not use the
FORCE INDEX,IGNORE INDEX,STRAIGHT_JOIN, orSQL_NO_CACHEsyntax in your production environment.To prevent implicit data type conversion, we recommend that you keep the type of the parameter value passed into the application by the SQL statement consistent with the type of the field in the database.
We recommend that you use the partitioning keys in the
WHEREclause of a DML statement for a partitioned table.The partition or subpartition name must be enclosed in parentheses in the statement. Here is an example:
obclient> SELECT * FROM tbl1_l2 PARTITION(p2,p3); +------+------+ | col1 | col2 | +------+------+ | 8 | 8 | | 9 | 9 | +------+------+ 2 rows in setA change made by a DML statement is persisted only when the transaction is committed. A DML statement can also be a transaction.
When you execute an
UPDATEstatement that involves hundreds of thousands of records without using theWHEREclause, a large transaction is generated. If the transaction is too large, the update may fail.Control the rows to be changed in an
UPDATEoperation to limit the transaction to a proper size.A
WHEREclause is optional in theDELETEstatement. If noWHEREclause is specified, all records in the table are deleted. If the statement involves hundreds of thousands of records, a large transaction is generated, which may reduce the performance. We recommend that you specify theWHEREclause to delete data in batches or use theTRUNCATE TABLEstatement.
If a cache table is subject to frequent DML operations, such as
INSERTorDELETE, and the data lifecycle is short, you must specify hints for queries.OceanBase Database allows you to perform Row Purge to recycle the resources of deleted nodes, which improves the query performance. Considering the diverse business scenarios, however, we recommend that you specify hints for queries to prevent performance degradation when the resources cannot be recycled by Row Purge.
To optimize the performance of the
DELETEorUPDATEstatement, we recommend that you do not perform the operation on more than 100 records, and use indexes in theWHEREclause.In comparison with a
DELETEstatement, aTRUNCATE TABLEstatement is faster and uses fewer system and transaction log resources. However, if no transaction is used in aTRUNCATEoperation, it cannot be rolled back. Therefore, we recommend that you proceed with caution when you use aTRUNCATE TABLEstatement.Note
A
TRUNCATE TABLEstatement is functionally equivalent to aDELETEstatement with noWHEREclause.