mybatis # and $

26 views
Skip to first unread message

dk

unread,
May 22, 2024, 11:09:05 PMMay 22
to mybatis-user
i have a sql to select from a table(about 17million rows)
when i use the sql in ssms it cost about 0.1s but when i run it in my java program it will cost
about 90s. (where condition) condition like concat(#{condition},'%')
what i do :
I replace #  to $ the program run as fast as  ssms

I really wonder what happen and  there any other way to solve the problem
mybatis version:3.5.6
mybatis-spring version:2.0.6

Guy Rouillier

unread,
May 23, 2024, 6:06:34 AMMay 23
to mybatis-user
You should get familiar with MyBatis User's Guide, if you haven't done so already. That document discusses the difference between parameters prefixed with a # vs those prefixed with a $.  In brief, the former denotes a SQL parameter marker, while the latter performs a string substitution.  Very different semantics.

--
Guy Rouillier


------ Original Message ------
From "dk" <pdk9...@gmail.com>
To "mybatis-user" <mybati...@googlegroups.com>
Date 5/22/2024 11:08:20 PM
Subject mybatis # and $

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/f372e10e-3a7d-4082-8dc2-41da42747c1en%40googlegroups.com.

Virus-free.www.avast.com

Iwao AVE!

unread,
May 24, 2024, 1:50:45 PMMay 24
to mybati...@googlegroups.com
Hello dk,

I've seen that before. It's MS SQL Server, right?
It's a long thread, but the solution was to specify sendStringParametersAsUnicode=false to the JDBC URL.

There is a lengthy, but important note section in the documentation. You should read it.

Regards,
Iwao

dk

unread,
May 25, 2024, 3:14:01 AMMay 25
to mybatis-user

yes,it's MS SQL Server,I add the param to my jdbc url before i ask,but it did't work

Iwao AVE!

unread,
May 25, 2024, 12:01:16 PMMay 25
to mybati...@googlegroups.com
I'm sorry to hear that. :(
With the information you provided, that probably is the only help you can get.

Just to clarify, MyBatis itself does not differentiate #{} and ${} when mapping the returned result set, so I'm pretty sure that the performance difference you are observing is not caused by MyBatis.

FYI, a similar issue was reported on the driver's tracker a while ago, however, the developers couldn't reproduce the problem.
Regards,
Iwao

dk

unread,
May 26, 2024, 1:13:57 AMMay 26
to mybatis-user
Ok,thanks for your  answer
Reply all
Reply to author
Forward
0 new messages