octosql icon indicating copy to clipboard operation
octosql copied to clipboard

mysql Relation = ‘in’

Open will2love opened this issue 5 years ago • 3 comments

origin code is this: //create a query with placeholders to prepare a statement from a physical formula query := formulaToSQL(filter, aliases) query = fmt.Sprintf("SELECT * FROM %s %s WHERE %s", tableName, alias, query)

when I use mysql sql: select m.test_id from mysql_test m where m.test_id in ('aaa') print the fileter: &{Value:true}

and then execute function formulaToSQL() get the sql SELECT * FROM test_config m WHERE TRUE

why in operation do not get corrent sql

will2love avatar May 06 '20 03:05 will2love

"In" predicates are not getting pushed down to SQL databases currently.

cube2222 avatar May 06 '20 07:05 cube2222

But why I test mysql use 'in' predicat: select m.test_id from mysql_test m where m.test_id in ('aaa')

it can get successful result .

this is why?

Can you explain how it works when 'in' predicates ? thks

will2love avatar May 09 '20 06:05 will2love

Yes, OctoSQL first planned query will actually be a whole database scan, followed by filtering in-memory. However, whenever we can, we push down predicates from in-memory filters to the underlying databases.

If you have a predicate like '=' then it will be pushed down, and octosql will only receive the records from the database which satisfy the predicate.

For a predicate like 'in' which is not yet implemented, OctoSQL will need to do a whole-table scan, and filter everything in memory to only the wanted records.

cube2222 avatar May 09 '20 07:05 cube2222