Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5165,9 +5165,9 @@ CREATE TABLE tab3 (
},
},
{
Query: "select unix_timestamp(d), unix_timestamp(tt) from t;",
Query: "select unix_timestamp(d), substring(cast(unix_timestamp(tt) as char(128)), -6) from t;",
Expected: []sql.Row{
{"1577898000", "1743140096.123456"},
{"1577898000", "123456"},
},
},
},
Expand Down Expand Up @@ -7799,6 +7799,40 @@ where
},
},
},
{
Name: "not expression optimization",
Dialect: "mysql",
SetUpScript: []string{
"create table t (i int);",
"insert into t values (123);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select * from t where 1 = (not(not(i)))",
Expected: []sql.Row{
{123},
},
},
{
Query: "select * from t where true = (not(not(i)))",
Expected: []sql.Row{
{123},
},
},
{
Query: "select * from t where true = (not(not(i = 123)))",
Expected: []sql.Row{
{123},
},
},
{
Query: "select * from t where false = (not(not(i != 123)))",
Expected: []sql.Row{
{123},
},
},
},
},
}

var SpatialScriptTests = []ScriptTest{
Expand Down
4 changes: 3 additions & 1 deletion sql/analyzer/optimization_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ func pushNotFiltersHelper(e sql.Expression) (sql.Expression, error) {
// NOT(NOT(c))=>c
if not, _ := e.(*expression.Not); not != nil {
if f, _ := not.Child.(*expression.Not); f != nil {
return pushNotFiltersHelper(f.Child)
if types.IsBoolean(f.Child.Type()) {
return pushNotFiltersHelper(f.Child)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions sql/types/typecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import (
"github.com/dolthub/go-mysql-server/sql"
)

// IsBoolean checks if t is a boolean type.
func IsBoolean(t sql.Type) bool {
return t == Boolean
}

// IsBlobType checks if t is BLOB
func IsBlobType(t sql.Type) bool {
if t == nil {
Expand Down
Loading