Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • erp5 erp5
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Merge requests 143
    • Merge requests 143
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Jobs
  • Commits
Collapse sidebar
  • nexedinexedi
  • erp5erp5
  • Merge requests
  • !2257

Draft: use INSERT .. ON DUPLICATE KEY UPDATE instead of REPLACE

  • Review changes

  • Download
  • Patches
  • Plain diff
Open Kazuhiko Shiozaki requested to merge on_duplicate_key_update into master Mar 09, 2026
  • Overview 16
  • Commits 9
  • Pipelines 0
  • Changes 17

By using INSERT .. ON DUPLICATE KEY UPDATE instead of REPLACE.

According to the document, if the row having the primary key already exists, 'INSERT .. ON DUPLICATE KEY UPDATE' will perform 'UPDATE' whereas 'REPLACE' will perform 'DELETE' + 'INSERT'. Thus the latter can be less efficient than a simple UPDATE because it involves more disk I/O and index maintenance, even when the data hasn't changed.

  • syncml (slow query found on prod)
  • versioning (slow query found on prod)
  • catalog (slow query found on prod)
  • full_text (slow query found on prod)
  • accounting_transaction (DELETE+INSERT pattern, number of rows per uid differ, 1 or 2)
  • stock (DELETE+INSERT pattern, number of rows per uid differ, many for Group Calendar Assignment, 1 or 2 for other portal types)
  • category (DELETE+INSERT pattern, not easy)

(SQLite3 equivalent is UPSERT > @xiaowu.zhang)

This merge request only focuses on simple REPLACE usage.

The important difference between INSERT .. ON DUPLICATE KEY UPDATE and REPLACE is the values of unspecified columns, which are reset to the default in the former, whereas are kept in the latter. This is why we have some = DEFAULT, for timestamp columns and security related columns, in this merge request.

/cc @vpelletier @jerome

Edited Mar 12, 2026 by Kazuhiko Shiozaki
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: on_duplicate_key_update
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7