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

Where condition doesn't work on the result of the subquery #7841

Closed
ghost opened this issue Jan 15, 2017 · 2 comments
Closed

Where condition doesn't work on the result of the subquery #7841

ghost opened this issue Jan 15, 2017 · 2 comments
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Jan 15, 2017

Hi

I'm trying to filter a result of a subquery, but the where condition doesn't work on the result of the subquery. The last result should list sub_gourp=1 and sub_group=2 only, but it includes also sub_group=3.

create database temp

use temp

insert test,my_group=1,sub_group=1 val=1
insert test,my_group=1,sub_group=2 val=1
insert test,my_group=1,sub_group=3 val=0

select * from test
	name: test
	time                my_group sub_group val
	----                -------- --------- ---
	1484407176627242006 1        1         1
	1484407179866974593 1        2         1
	1484407185003410148 1        3         0

select * from (select * from test where my_group='1' group by sub_group order by desc limit 1) group by sub_group
	name: test
	tags: sub_group=3
	time                my_group val
	----                -------- ---
	1484407185003410148 1        0

	name: test
	tags: sub_group=2
	time                my_group val
	----                -------- ---
	1484407179866974593 1        1

	name: test
	tags: sub_group=1
	time                my_group val
	----                -------- ---
	1484407176627242006 1        1

select * from (select * from test where my_group='1' group by sub_group order by desc limit 1) where val > 0 group by sub_group
	name: test
	tags: sub_group=3
	time                my_group val
	----                -------- ---
	1484407185003410148 1        0

	name: test
	tags: sub_group=2
	time                my_group val
	----                -------- ---
	1484407179866974593 1        1

	name: test
	tags: sub_group=1
	time                my_group val
	----                -------- ---
	1484407176627242006 1        1

My first mistake was comparing val with '0' (#7646), but even comparing with 0 the result is the same. Does anyone have a suggestion

@jsternberg
Copy link
Contributor

I need to investigate, but @jwilder should I add this to the 1.2 milestone?

@jsternberg
Copy link
Contributor

I'm looking at this now. We don't propagate the condition of the outer query at all and it doesn't get applied anywhere. I'm looking at it now, but this is pretty difficult. @jwilder if I'm unable to resolve this, we may have to put a caveat down that conditions don't work correctly yet.

/cc @rkuchan

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

3 participants