From 826e6fcdd86c413cffd776cbe1877483d1430511 Mon Sep 17 00:00:00 2001 From: Vilnis Termanis Date: Sat, 20 Jan 2018 17:00:59 +0000 Subject: [PATCH] Reduce callproc roundtrip time - Make only one single call to SET variables used as procedure parameters (rather than one per parameter, to be in line with procedure OUT/INOUT retrieval). --- lib/mysql/connector/cursor.py | 11 +++++++++-- lib/mysql/connector/cursor_cext.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/mysql/connector/cursor.py b/lib/mysql/connector/cursor.py index 2b549f9..a9f44a8 100644 --- a/lib/mysql/connector/cursor.py +++ b/lib/mysql/connector/cursor.py @@ -739,16 +739,23 @@ def callproc(self, procname, args=()): argnames = [] argtypes = [] if args: + argvalues = [] for idx, arg in enumerate(args): argname = argfmt.format(name=procname, index=idx + 1) argnames.append(argname) if isinstance(arg, tuple): argtypes.append(" CAST({0} AS {1})".format(argname, arg[1])) - self.execute("SET {0}=%s".format(argname), (arg[0],)) + argvalues.append(arg[0]) else: argtypes.append(argname) - self.execute("SET {0}=%s".format(argname), (arg,)) + argvalues.append(arg) + + self.execute( + "SET %s" % ','.join('{0}=%s'.format(arg) + for arg in argnames), + argvalues + ) call = "CALL {0}({1})".format(procname, ','.join(argnames)) diff --git a/lib/mysql/connector/cursor_cext.py b/lib/mysql/connector/cursor_cext.py index 41f120f..e9462f6 100644 --- a/lib/mysql/connector/cursor_cext.py +++ b/lib/mysql/connector/cursor_cext.py @@ -415,16 +415,23 @@ def callproc(self, procname, args=()): argnames = [] argtypes = [] if args: + argvalues = [] for idx, arg in enumerate(args): argname = argfmt.format(name=procname, index=idx + 1) argnames.append(argname) if isinstance(arg, tuple): argtypes.append(" CAST({0} AS {1})".format(argname, arg[1])) - self.execute("SET {0}=%s".format(argname), (arg[0],)) + argvalues.append(arg[0]) else: argtypes.append(argname) - self.execute("SET {0}=%s".format(argname), (arg,)) + argvalues.append(arg) + + self.execute( + "SET %s" % ','.join('{0}=%s'.format(arg) + for arg in argnames), + argvalues + ) call = "CALL {0}({1})".format(procname, ','.join(argnames))