#12132: possibly unneccessary unique_check for primary key fields is models ------------------------------------------------+--------------------------- Reporter: Mark | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: soc2009/model-validation Keywords: model-validation validation unique | Stage: Unreviewed Has_patch: 1 | ------------------------------------------------+--------------------------- Every time a clean() method of the model instance is run, validate_unique() is performed. It seems, that _get_unique_checks doesn't get into account, that the primary key doesn't need such a check. The sql that is run during the check is meaningless (it is only meaningless if we are checking a primary key field):
{{{ SELECT (1) AS "a" FROM "test_models_testmodel" WHERE ("test_models_testmodel"."id" = 1 AND NOT ("test_models_testmodel"."id" = 1 )) }}} This results in unnecessary database hits and (possible) performance degradation. I have put together a simple test rack, so that the effect can be easily observed. It's not a real test case, but I really hope, that it will be sufficient. If I understand correctly, it can be easily fixed, by checking if a field is a primary key inside the _get_unique_checks model instance method (patch included). -- Ticket URL: <http://code.djangoproject.com/ticket/12132> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---