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

When GROUP BY and ORDER BY aliases are inconsistent, stream merging should be used #557

Closed
wanghuanwei opened this issue Jan 15, 2018 · 2 comments

Comments

@wanghuanwei
Copy link

wanghuanwei commented Jan 15, 2018

Please answer these questions before submitting your issue. Thanks!

Which version of Sharding-Jdbc do you using?

sharingJdbc1.5.0

Expected behavior

Actual behavior

select语句中,当groupBy和orderBy的字段一样时,也会出现内存归并的情况,拉取全部数据进行merge。类似下面的SQL:
SELECT
co.id orderId,
co.order_no orderNo,
co.payer_type payerType,
co.id AS GROUP_BY_DERIVED_0 (这个是SQL改写之后,追加的别名,和select定义的冲突,导致alias不一致)
FROM
t1 co
LEFT JOIN t2 odt ON co.id = odt.order_id
WHERE
co.create_time BETWEEN '2018-01-01'
AND '2018-01-15'
GROUP BY
co.id DESC
ORDER BY
co.id DESC

完整实例SQL:
SELECT
co.id orderId,
co.order_no orderNo,
co.combo_name comboName,
co.combo_code comboCode,
co.buyer_id buyerId,
co.buyer_domain_id buyerDomainId,
co.buyer_name buyerName,
co.buyer_mobile buyerMobile,
co.buyer_real_name buyerRealName,
co.creator_id creatorId,
co.creator_name creatorName,
co.creator_work_no creatorWorkNo,
co.creator_real_name creatorRealName,
co.amount amount,
co.actual_amount actualAmount,
co.status status,
co.create_time createTime,
co.last_update_time updateTime,
co.creator_org_id orgId,
co.creator_org_name orgName,
co.pay_type payType,
co.payer_type payerType
FROM
combo_order co LEFT JOIN order_detail odt ON co.id = odt.order_id
WHERE
AND co.create_time between #{conditions.createTimeBegin} and #{conditions.createTimeEnd}
GROUP BY
co.id DESC
ORDER BY
co.id DESC LIMIT #{start},#{ps}

Steps to reproduce the behavior

Please provide the reproduce example codes (such as github link) if possible.

@terrymanu
Copy link
Member

应该是别名导致的多余的补列导致的问题

terrymanu added a commit that referenced this issue Jan 17, 2018
terrymanu added a commit that referenced this issue Jan 17, 2018
terrymanu added a commit that referenced this issue Jan 17, 2018
@terrymanu
Copy link
Member

fixed at 2.0.2

@terrymanu terrymanu self-assigned this Jan 17, 2018
@terrymanu terrymanu changed the title Select时同时存在GroupBy和OrderBy且item一样时存在内存归并的情况 When GROUP BY and ORDER BY aliases are inconsistent, stream merging should be used Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants