I took a lok at Mysql 5.0.91 BIGINT column value comparison with '1' to check if there is some best practices for BigInt but found nothing.
I have a column that is BigInt(20) and my query has a WHERE clause that compares the column of type BigInt IN (). This has a major impact on the performance. Althought I have an index for that when I don't use this IN condition the query performance increases a lot.
So what is the best way to do that comparison I need? IN () is a good practice or there is a best approach?
Table Description (Obfuscated for security reasons)
Field,Type,Null,Key,Default,Extra
id,bigint(20),NO,PRI,NULL,auto_increment
status,varchar(64),NO,,NULL,
dono_id,bigint(20),YES,,NULL,
dono_tipo,varchar(64),YES,MUL,NULL,
MyBigIntField,bigint(20),YES,MUL,NULL
QUERY
explain select
DISTINCT(MyBigIntField)
FROM
MyTable
WHERE
MyBigIntField IN ('16', '49', '58', '155', '226')
AND NOT (status = 'Failure')
AND dono_id <> 1106
and dono_tipo = 'Purchase';
Execution Plan
EXPLAIN
"{
"query_block": {
"select_id": 1,
"cost_info": {
"query_cost": "23.21"
},
"duplicates_removal": {
"using_filesort": false,
"table": {
"table_name": "MyTable",
"access_type": "range",
"possible_keys": [
"idx_MyTable_owner",
"IDX_MyTable_PI"
],
"key": "IDX_MyTable_PI",
"used_key_parts": [
"MyBigIntField"
],
"key_length": "9",
"rows_examined_per_scan": 13,
"rows_produced_per_join": 5,
"filtered": "45.00",
"index_condition": "(`MyDatabase`.`MyTable`.`MyBigIntField` in (16,49,58,155,226))",
"cost_info": {
"read_cost": "22.04",
"eval_cost": "1.17",
"prefix_cost": "23.21",
"data_read_per_join": "231K"
},
"used_columns": [
"id",
"status",
"dono_id",
"dono_tipo",
"MyBigIntField"
],
"attached_condition": "((`MyDatabase`.`MyTable`.`status` <> 'Failure') and (`MyDatabase`.`MyTable`.`dono_id` <> 1106) and (`MyDatabase`.`MyTable`.`dono_tipo` = 'Purchase'))"
}
}
}
}"