-
I've read this post and documentation but I'm still confused. What's explained :
So, from what I understand, from <variable declarations>
where <formula>
select <expression> From what I understand CodeQL doesn't return the same tuple result twice. identical result are merged. This is why the request in the other post was returning 1. However here's a simple case where this is clearly not the case : class SmallInt extends int {
SmallInt() {
this in [5..15]
}
}
class TenMult extends int{
TenMult(){
exists(int k | k in [0..10] and this = 10*k)
}
} from SmallInt i, TenMult tm
where
tm = i
or tm =i+1
select tm, i The above request return :
Nothing unusual. from SmallInt i, TenMult tm
where
tm = i
or tm =i+1
select tm The above request return :
which I also understand. Because there was However, I can't make sens of this request : select count(SmallInt i, TenMult tm|
tm = i or
tm = i+1
| tm) The above request return :
Which I don't understand at all ! Actually, after some tries I got this request which returns 1, as expected (this also solved my problem for the real request I was writting) select count(TenMult tm|
exists(SmallInt i |
tm = i or
tm = i+1
)
| tm) However I have no idea why the version without the EDIT : after some more testing, i looks like (9,10) and (10,10), the
Those 2 requests return the same result, even if it's obvious than bindingset[e]
int foo(int e){
result= 1
}
select count(SmallInt i, TenMult tm |
tm = i or
tm = i+1
| foo) select count(SmallInt i, TenMult tm |
tm = i or
tm = i+1
| 1 ) EDIT 2
My 2 questions above still holds, I don't understand the logic behind it at all. And now I'm convinced that the documentation about Also, VScode syntax coloration is wrong. In the following request it consider class OneTwoThree extends int{
OneTwoThree(){
this = 1 or this = 2 or this = 3
}
}
select count(OneTwoThree ott | | 1)
//returns 3 Not sure about this but it seems like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thank you for the questions @ayosten, I hope I'll be able to help.
Note the precise wording here: the distinct values for each possible assignment of the aggregation variables are counted - they do not have to be distinct across different assignments. Consider the following example: class SmallInt extends int {
SmallInt() { this in [5 .. 15] }
}
int foo(SmallInt i) { result in [i - 1, i, 1] }
select count(SmallInt i | | foo(i))
To bring this to its logical conclusion:
As explained above, this is not correct.
Agreed, VScode should not complain about this. Thank you for bringing it to our attention - I have opened an internal bug report. |
Beta Was this translation helpful? Give feedback.
Thank you for the questions @ayosten, I hope I'll be able to help.
Note the precise wording here: the distinct values for each possible assignment of the aggregation variables are counted - they do not have to be distinct across different assignments.
Consider the following example:
i
(5, 6, ..., 14, 15).