Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#1073 closed defect (wontfix)

method_save in meta/__init__.py could make use of mysql features

Reported by: Ian@… Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: dev@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I was looking at method_save, and noticed it might not be the best way of doing it for mysql

in mysql you have got 2 features which might help out a bit.

REPLACE [LOW_PRIORITY | DELAYED]
    [INTO] tbl_name [(col_name,...)]
    VALUES ({expr | DEFAULT},...),(...),...

http://dev.mysql.com/doc/refman/5.0/en/replace.html

which will replace the record if it already exists

and

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name [(col_name,...)]
    VALUES ({expr | DEFAULT},...),(...),...
    [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]

http://dev.mysql.com/doc/refman/5.0/en/insert.html

with the ON DUPLICATE KEY UPDATE part allowing you to deal with a duplicate record.

using one of these might simplify the logic going on here, as well as possibly reducing the number of trips to the DB server.

Change History (4)

comment:1 Changed 10 years ago by anonymous

  • Component changed from Admin interface to Database wrapper
  • Summary changed from method_save in meta/__init__.py could make use of mysql features to method_save in meta/__init__.py could make use of mysql features

comment:2 Changed 10 years ago by adrian

This would be a pretty good improvement, I think.

comment:3 Changed 9 years ago by Simon Greenhill, dev@…

  • Cc dev@… added

Just a few points to consider

1) When using InnoDB tables REPLACE INTO will silently delete anything in other tables that reference the replaced field with an ON DELETE CASCADE constraint. This can be quite shocking if you're not expecting it.

2) REPLACE INTO is veeeeeeery slow when compared with an UPDATE.

comment:4 Changed 9 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to closed

Closing as a wontfix due to the reasons pointed out by Simon Greenhill.

Note: See TracTickets for help on using tickets.
Back to Top