OceanBase
English日本語简体中文
ドキュメントホーム
製品
エコシステム
リリース

データベース

OceanBase CloudOceanBaseデータベース

データベース

OceanBase CloudOceanBaseデータベース
OceanBase CloudOceanBaseデータベース

OceanBaseデータベース

KV - V4.4.2
  • OBKVの概要
  • OBKVのアーキテクチャ
  • OBKV-Table
    • OBKV-Table概要
      • OBKV-Tableの概要
      • OBKV-Tableのコア機能
      • OBKV-Tableデプロイの概要
    • シンプルなKey-Valueストレージのクイックスタート(Java)
    • OBKV-Table Javaクライアントを使ったアプリケーション開発
      • OBKV-Table Java開発ガイド
      • OBKV-Table開発の準備
      • OBKV-Table Javaクライアントを使用してクラスタに接続する
      • OBKV-Table操作例
        • OBKV-Tableへのデータ書き込み
        • OBKV-Tableによるデータのクエリ
        • OBKV-Tableでのデータ更新
        • OBKV-Tableによるデータの削除
      • OBKV-Table Javaクライアントのパラメータ設定
    • OBKV-Table管理
      • OBKV-Table管理の概要
      • OBKV-Tableの高可用性
      • OBKV-Tableのセキュリティ権限
      • OBKV-Tableモニタリングメトリクス
    • OBKV-Tableリファレンス
      • OBKV-Tableのデータモデル
      • OBKV-Tableの操作タイプ
      • OBKV-Tableがサポートするデータ型
      • OBKV-Table全文インデックス
      • OBKV-Tableのグローバルインデックスの使用範囲と例
      • OBKV-Tableの期限切れデータ削除
      • OBKV-Tableのグループコミット
      • OBKV-Tableの弱い整合性読み取りと最寄りデータセンターからの読み取り
      • OBKV-Table関連ビュー
    • OBKV-Table よくある質問
  • OBKV-HBase
    • OBKV-HBaseの概要
    • OBKV-HBaseのコア機能
    • OBKV-HBaseのデプロイ
    • OBKV-HBaseによるアプリケーション開発
      • OBKV-HBase アプリケーション開発の概要
      • OBKV-HBase Javaクライアントを使用したクラスタへの接続
      • HBaseの業務コードをOBKV-HBaseに移行する
      • OBKV-HBase データ操作の例
    • OBKV-HBase 移行ガイド
    • OBKV-HBase管理
      • OBKV-HBase管理の概要
      • OBKV-HBaseの高可用性
      • OBKV-HBaseのセキュリティ権限
      • OBKV-HBaseモニタリングメトリクス
    • OBKV-HBaseクエリの最適化
    • OBKV-HBaseの性能テスト
    • OBKV-HBaseリファレンス
      • OBKV-HBaseデータモデル
      • OBKV-HBaseのデータスキーマ
      • HBaseとの互換インターフェース
      • HBaseと互換性のあるフィルター
      • OBKV-HBaseの自動パーティション分割
      • OBKV-HBaseにおける期限切れデータの削除
      • OBKV-HBaseの弱い整合性読み取りと最寄りデータセンターからの読み取り
      • OBKV-HBase関連ビュー
    • OBKV-HBaseエコシステム統合
      • Flink連携
        • Flinkコネクタを使用してOBKV-HBaseにデータを同期する
        • ネイティブFlinkによるOBKV-HBaseへのアクセス
      • HiveによるOBKV-HBaseへのアクセス
      • SparkによるOBKV-HBaseへのアクセス
  • OBKVリリースノート
    • OBKV Enterprise版

PDF をダウンロード

このページには現在中国語/日本語版がなく、英語版を表示しています。
ドキュメントフィードバック
  1. ドキュメントセンター
  2. OceanBaseデータベース
  3. KV
  4. V4.4.2

Differences between replace and insert_or_update

最終更新:2026-09-04 10:25:15

insert_or_update
replace

replace and insert_or_update are two operations that can be easily confused. In many cases, they may appear to have the same behavior externally, but their underlying semantics differ. This topic will provide a detailed explanation of the differences between the two.

replace represents an insertion operation. When conflicts occur, it deletes all rows causing conflicts and then performs the insertion.

insert_or_update also represents an insertion operation. However, when conflicts occur, it performs an update operation instead.

Let's illustrate the differences between the two with examples.

insert_or_update

The insert_or_update operation provided by OBKV-Table is equivalent to a special SQL syntax. The following example shows how insert_or_update works:

OceanBase (root@test)> desc test_replace;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| c1    | int(11) | NO   | PRI | NULL    |       |
| c2    | int(11) | YES  |     | NULL    |       |
| c3    | int(11) | YES  | UNI | NULL    |       |
+-------+---------+------+-----+---------+-------+
3 rows in set (0.03 sec)

OceanBase (root@test)> select * from test_replace;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 |    2 |    3 |
|  4 |    5 |    6 |
+----+------+------+
2 rows in set (0.03 sec)

OceanBase (root@test)> insert into test_replace (c1, c2, c3) values (4, 7, 8), (5, 8, 9) on duplicate key update c1=values(c1), c2=values(c2), c3=values(c3);
Query OK, 3 rows affected (0.03 sec)
Records: 2  Duplicates: 1  Warnings: 0

OceanBase (root@test)> select * from test_replace;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 |    2 |    3 |
|  4 |    7 |    8 |
|  5 |    8 |    9 |
+----+------+------+
3 rows in set (0.03 sec)

replace

OceanBase (root@test)> select * from test_replace;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 |    2 |    3 |
|  4 |    7 |    8 |
|  5 |    8 |    9 |
+----+------+------+
3 rows in set (0.03 sec)

OceanBase (root@test)> replace into test_replace (c1, c3) values (4, 9);
Query OK, 3 rows affected (0.04 sec)

OceanBase (root@test)> select * from test_replace;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 |    2 |    3 |
|  4 | NULL |    9 |
+----+------+------+
2 rows in set (0.02 sec)

Based on the preceding examples, unlike insert_or_update, the replace operation deletes rows and changes the value of c2 in the row where c1 is 4 to the default value NULL because of the insertion of a new value. The insert_or_update operation does not perform these two special actions. In most cases, you need to use the insert_or_update operation, which is similar to the put method in NoSQL mode.

The two operations achieve the same results in the following two circumstances:

  • The table only has the primary key but no unique indexes.

  • The operation specifies the values of all columns in a row and the system does not need to insert the default value for columns where values are missing.

Although the results are the same in the preceding two circumstances, OBKV-Table optimizes the implementation of insert_or_update to provide better performance than that of replace.

次のトピック

OBKVの概要
次へ
このページの内容
insert_or_update
replace