Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pagehelper-spring-boot-starter1.2.11 sqlserver分页,查询总数的时候,连接查询加入with(nolock)之后,sql解析不对 on条件丢失 #76

Closed
Burt-L opened this issue Jun 4, 2019 · 6 comments

Comments

@Burt-L
Copy link

Burt-L commented Jun 4, 2019

#66
实际sql:SELECT *
FROM
forum_post_info a with(nolcok)
LEFT JOIN forum_carcase_tags as b whth(nolock) on a.id = b.carcase_id where b.tag_id = 127
pagehelper生成的count语句:
SELECT count(0)
FROM
forum_post_info a with(nolcok)
LEFT JOIN forum_carcase_tags as b whth(nolock) where b.tag_id = 127

插件生成的count语句,on条件丢失。

pagehelper-spring-boot-starter 升到了1.2.11 还是有这个问题。net.sf.jsqlparser.parser.CCJSqlParserUtil#parse(java.lang.String) 入参的sql有on条件,但是转换之后on条件丢失了。

@Burt-L
Copy link
Author

Burt-L commented Jun 4, 2019

按com.github.pagehelper.PageInterceptor#count
MappedStatement countMs = ExecutorUtil.getExistedMappedStatement(ms.getConfiguration(), countMsId);
手写计算count的sql,但是后续的生成的分页sql依旧丢失了on条件

@Burt-L
Copy link
Author

Burt-L commented Jun 4, 2019

pagehelper分页插件配置如下:
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper.pageSizeZero=true
pagehelper.autoRuntimeDialect=true

@Burt-L Burt-L changed the title sqlserver分页,查询总数的时候,连接查询加入with(nolock)之后,sql解析不对 on条件丢失 pagehelper-spring-boot-starter1.2.11 sqlserver分页,查询总数的时候,连接查询加入with(nolock)之后,sql解析不对 on条件丢失 Jun 4, 2019
@abel533
Copy link
Collaborator

abel533 commented Jun 5, 2019

forum_post_info a with(nolcok)

forum_carcase_tags as b whth(nolock)

看出原因了吗?

排除上述两个书写错误后,生成的分页SQL如下:

SELECT COUNT(0)
FROM forum_post_info a WITH (NOLOCK)
	LEFT JOIN forum_carcase_tags b WITH (NOLOCK) ON a.id = b.carcase_id
WHERE b.tag_id = 127

-------------------

SELECT TOP 10 *
FROM (
	SELECT ROW_NUMBER() OVER (ORDER BY RAND()) AS PAGE_ROW_NUMBER, *
	FROM (
		SELECT *
		FROM forum_post_info a WITH (NOLOCK)
			LEFT JOIN forum_carcase_tags b WITH (NOLOCK) ON a.id = b.carcase_id
		WHERE b.tag_id = 127
	) PAGE_TABLE_ALIAS
) PAGE_TABLE_ALIAS
WHERE PAGE_ROW_NUMBER > 1
ORDER BY PAGE_ROW_NUMBER

abel533 added a commit to pagehelper/Mybatis-PageHelper that referenced this issue Jun 5, 2019
@abel533
Copy link
Collaborator

abel533 commented Jun 5, 2019

找到你失败的原因了。。

默认的 ReplaceSql 支持不了,应该选择 regex 方式,参考:

pagehelper/Mybatis-PageHelper@1801260

pagehelper/Mybatis-PageHelper@780357a

明天发布 5.1.10 版本,仅仅修改一个默认值。

@abel533 abel533 closed this as completed Jun 5, 2019
@Burt-L
Copy link
Author

Burt-L commented Jun 6, 2019

感谢您百忙之中帮忙看问题,谢谢!经验证regex 方式可以正常分页。再次感谢!

@Burt-L
Copy link
Author

Burt-L commented Jun 6, 2019

奉上咖啡一杯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants