Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3151 closed enhancement (fixed)

[patch] "SET NAMES utf8" is sent before every query

Reported by: smurf@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: minor Keywords: mysql
Cc: mir@…, dev@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

No, we do not need to send a "SET NAMES utf8" to the server before every
mysql request. Just before the first one.

Depending on the latency of your database connection and/or the prevalence of cached queries,
this change may significantly reduce your response time.

diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index e7e060e..28c5b1c 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -98,9 +98,11 @@ class DatabaseWrapper(local):
                 kwargs['port'] = int(settings.DATABASE_PORT)
             kwargs.update(self.options)
             self.connection = Database.connect(**kwargs)
-        cursor = self.connection.cursor()
-        if self.connection.get_server_info() >= '4.1':
-            cursor.execute("SET NAMES 'utf8'")
+            cursor = self.connection.cursor()
+            if self.connection.get_server_info() >= '4.1':
+                cursor.execute("SET NAMES 'utf8'")
+        else:
+            cursor = self.connection.cursor()
         if settings.DEBUG:
             return util.CursorDebugWrapper(MysqlDebugWrapper(cursor), self)
         return cursor

Attachments (1)

3151.diff (814 bytes ) - added by dev@… 18 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by anonymous, 18 years ago

Cc: mir@… added

comment:2 by dev@…, 18 years ago

Cc: dev@… added
Keywords: mysql added
Version: SVN

Passes all tests using the mysql backend at r4227.

----------------------------------------------------------------------
Ran 66 tests in 14.864s

OK

comment:3 by dev@…, 18 years ago

Summary: "SET NAMES utf8" is sent before every query[patch] "SET NAMES utf8" is sent before every query

by dev@…, 18 years ago

Attachment: 3151.diff added

comment:4 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [4267]) Fixed #3151 -- Improved MySQL backend not to send 'SET NAMES utf8' before every query. Thanks for the patch, smurf@…

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