select ...
from products p
join product_categories pc on pc.id = p.product_category_id
(many more joins)
where p.id in ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ...)
==> Parameters: 18310573(Long), 44478123(Long), 17805559(Long), 41610962(Long), 16733361(Long), 51136262(Long), 18676625(Long), 17242776(Long), 17322051(Long), 17322031(Long), 43392127(Long), 17338259(Long), 16738428(Long), 17203169(Long), 16896876(Long), 16726746(Long), 44478130(Long), 18733088(Long), 18572799(Long), 44478138(Long),....
select ...
from products p
join product_categories pc on pc.id = p.product_category_id
(many more joins)
where p.id in ( 18310573,
44478123,
17805559,
41610962,
16733361,
....)
public BoundSql getBoundSql(Object parameterObject)--
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.
For more options, visit https://groups.google.com/d/optout.
|
This email has been checked for viruses by Avast antivirus software.
|
You forgot to mention the most important part: how you are defining the query in MyBatis. For example, if your foreach is formatted like this:<foreach collection="myList" item="item" open="(" separator="," close=")">
#{item, jdbcType=INTEGER}
</foreach>Then that is where your newline is coming from. You can avoid that by simply putting everything shown above on a single line.
<if collection="list" test="list != null">
p.id in
<foreach item="item" collection="list" open="(" separator="," close=")">
{ "item"? }
</foreach>
</if>
<if collection="list" test="list != null">
p.id in <foreach item="item" collection="list" open="(" separator="," close=")">{ "item"? }</foreach>
</if>
Hello,I am using the mybatis <foreach> statement in one of my sql queries. mybatis generates a prepared statement that I can see in the logs:select ...
from products p
join product_categories pc on pc.id = p.product_category_id
(many more joins)
where p.id in ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ...)==> Parameters: 18310573(Long), 44478123(Long), 17805559(Long), 41610962(Long), 16733361(Long), 51136262(Long), 18676625(Long), 17242776(Long), 17322051(Long), 17322031(Long), 43392127(Long), 17338259(Long), 16738428(Long), 17203169(Long), 16896876(Long), 16726746(Long), 44478130(Long), 18733088(Long), 18572799(Long), 44478138(Long),....
Everything is working fine even though the query contains many joins and a long list of parameters that I have truncated to avoid filling the space unnecessarily.I also have to tell you that we log slow queries at the postgresql level with the following option log_min_duration_statement.The problem comes from the fact that either mybatis generates a sql query with one parameter per line or postgresql logs the query with one parameter per line.Here is how the query is logged in the postgresql logs:select ...
from products p
join product_categories pc on pc.id = p
...
and{ ?("uBound", jdbcType = JdbcType.INTEGER) }
> pl.id
and pl.id >={ ?("lBound", jdbcType = JdbcType.INTEGER) }
--
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.
For more options, visit https://groups.google.com/d/optout.