select: Return early from bool AND, OR (#13914)

Return as soon as an AND fails and whenever an OR succeeds. Faster and more flexible.

For example makes `select * from S3object where _2 != '' AND _2 > 1` able to operate on empty fields.

Followup to #13900
This commit is contained in:
Klaus Post 2021-12-15 16:47:21 -08:00 committed by GitHub
parent da540ccf8c
commit 91f72f25ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -794,6 +794,14 @@ func TestCSVQueries2(t *testing.T) {
query: `select * from S3object where _2 IS NOT ''`,
wantResult: `{"c1":"1","c2":"2","c3":"3"}`,
},
{
name: "select-is_not_string",
input: []byte(`c1,c2,c3
1,2,3
1,,3`),
query: `select * from S3object where _2 != '' AND _2 > 1`,
wantResult: `{"c1":"1","c2":"2","c3":"3"}`,
},
}
defRequest := `<?xml version="1.0" encoding="UTF-8"?>

View File

@ -69,6 +69,9 @@ func (e *Expression) evalNode(r Record, tableAlias string) (*Value, error) {
if !ok {
return nil, errExpectedBool
}
if b {
return FromBool(true), nil
}
result = result || b
}
return FromBool(result), nil
@ -91,6 +94,9 @@ func (e *AndCondition) evalNode(r Record, tableAlias string) (*Value, error) {
if !ok {
return nil, errExpectedBool
}
if !b {
return FromBool(false), nil
}
result = result && b
}
return FromBool(result), nil