Skip to content

Commit 093d559

Browse files
committed
BUG#27426532: Reduce callproc roundtrip time
The cursors (both pure and c-ext versions) uses a single SELECT query to retrieve procedure result parameters after a procedure call. However, to set the input parameters, one SET call is used per parameter. For any procedures with more than one parameter this results in more queries than necessary and ultimately the callproc call takes longer. With this patch just a single SET call is made. Thank you for the contribution. Change-Id: Icac72d24638bd465e336033185058577740ca7d6
1 parent ca53ee5 commit 093d559

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ v8.0.32
2222
- BUG#32625155: Tests fail against group replication cluster
2323
- BUG#30089671: Fix decoding VARBINARY columns when using a prepared cursor
2424
- BUG#28020811: Fix multiple reference leaks in the C extension
25+
- BUG#27426532: Reduce callproc roundtrip time
2526
- BUG#24364556: Improve warning behavior
2627

2728
v8.0.31

lib/mysql/connector/cursor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,15 +802,19 @@ def callproc(
802802
# by '.' and grab the procedure name from procname.
803803
procname_abs = procname.split(".")[-1]
804804
if args:
805+
argvalues = []
805806
for idx, arg in enumerate(args):
806807
argname = argfmt.format(name=procname_abs, index=idx + 1)
807808
argnames.append(argname)
808809
if isinstance(arg, tuple):
809810
argtypes.append(f" CAST({argname} AS {arg[1]})")
810-
self.execute(f"SET {argname}=%s", (arg[0],))
811+
argvalues.append(arg[0])
811812
else:
812813
argtypes.append(argname)
813-
self.execute(f"SET {argname}=%s", (arg,))
814+
argvalues.append(arg)
815+
816+
placeholders = ",".join(f"{arg}=%s" for arg in argnames)
817+
self.execute(f"SET {placeholders}", argvalues)
814818

815819
call = f"CALL {procname}({','.join(argnames)})"
816820

lib/mysql/connector/cursor_cext.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,19 @@ def callproc(
519519
# by '.' and grab the procedure name from procname.
520520
procname_abs = procname.split(".")[-1]
521521
if args:
522+
argvalues = []
522523
for idx, arg in enumerate(args):
523524
argname = argfmt.format(name=procname_abs, index=idx + 1)
524525
argnames.append(argname)
525526
if isinstance(arg, tuple):
526527
argtypes.append(f" CAST({argname} AS {arg[1]})")
527-
self.execute(f"SET {argname}=%s", (arg[0],))
528+
argvalues.append(arg[0])
528529
else:
529530
argtypes.append(argname)
530-
self.execute(f"SET {argname}=%s", (arg,))
531+
argvalues.append(arg)
532+
533+
placeholders = ",".join(f"{arg}=%s" for arg in argnames)
534+
self.execute(f"SET {placeholders}", argvalues)
531535

532536
call = f"CALL {procname}({','.join(argnames)})"
533537

0 commit comments

Comments
 (0)