Mysql 分割槽處理NULL值的方式

2021-07-16 09:43:44 字數 3907 閱讀 9460

一般情況下,mysql的分割槽把null當做零值,或者乙個最小值進行處理

對於range分割槽

create table test_null(

id int

)partition by range(id)(

partition p0 values less than (-6),

partition p1 values less than (0),

partition p2 values less than (1),

partition p3 values less than maxvalue

);mysql> insert into test_null values(null);

query ok, 1 row affected (0.01 sec)

mysql> select

-> partition_name part,

-> partition_expression expr,

-> partition_description descr,

-> table_rows

-> from information_schema.partitions where

-> table_schema = schema()

-> and table_name='test_null';

+------+------+----------+------------+

| part | expr | descr | table_rows |

+------+------+----------+------------+

| p0 | id | -6 | 1 |

| p1 | id | 0 | 0 |

| p2 | id | 1 | 0 |

| p3 | id | maxvalue | 0 |

+------+------+----------+------------+

4 rows in set (0.00 sec)

對於list分割槽

當分割槽定義不包含null值是,會報錯

create table list_null(

id int

)partition by list(id)(

partition p1 values in (0),

partition p2 values in (1)

);mysql> insert into list_null values(null);

error 1526 (hy000): table has no partition

for value null

當分割槽定義包含null時

create table list_null_1(

id int

)partition by list(id)(

partition p1 values in (0),

partition p2 values in (1),

partition p3 values in (null)

);mysql> insert into list_null_1 values(null);

query ok, 1 row affected (0.01 sec)

mysql> select

-> partition_name part,

-> partition_expression expr,

-> partition_description descr,

-> table_rows

-> from information_schema.partitions where

-> table_schema = schema()

-> and table_name='list_null_1';

+------+------+-------+------------+

| part | expr | descr | table_rows |

+------+------+-------+------------+

| p1 | id | 0 | 0 |

| p2 | id | 1 | 0 |

| p3 | id | null | 1 |

+------+------+-------+------------+

3 rows in set (0.00 sec)

對於hash分割槽和key分割槽

create table hash_null(

id int

)partition by hash(id)

partitions 2;

mysql> insert into hash_null values(null);

query ok, 1 row affected (0.00 sec)

mysql> select

-> partition_name part,

-> partition_expression expr,

-> partition_description descr,

-> table_rows

-> from information_schema.partitions where

-> table_schema = schema()

-> and table_name='hash_null';

+------+------+-------+------------+

| part | expr | descr | table_rows |

+------+------+-------+------------+

| p0 | id | null | 1 |

| p1 | id | null | 0 |

+------+------+-------+------------+

2 rows in set (0.00 sec)

對於key分割槽

create table key_null(

id int

)partition by key(id)

partitions 2;

mysql> select

-> partition_name part,

-> partition_expression expr,

-> partition_description descr,

-> table_rows

-> from information_schema.partitions where

-> table_schema = schema()

-> and table_name='key_null';

+------+------+-------+------------+

| part | expr | descr | table_rows |

+------+------+-------+------------+

| p0 | `id` | null | 1 |

| p1 | `id` | null | 0 |

+------+------+-------+------------+

MySQL 處理 null 值的問題

mysql中null是不參與計算的,對null進行計算,使用 is null 和 is not null 運算子 只有 才支援null的比較,其他比較運算對有null運算元時返回的結果就是null,永遠返回false,即 null null 返回false 結論 如果在not in子查詢中有null...

mysql之null值處理函式

ifnull expr1,expr2 如果第乙個引數 expr1 不為null則直接返回它,否則返回第二個引數 expr2。返回值是數字或者字串。它相當於oracle中的nvl函式 select ifnull 1,0 select ifnull null,10 select ifnull 1 0,y...

空值NULL處理

1.空值 null 處理 查詢籍貫為null同學 如果判斷乙個欄位的的值是不是null,需要使用is關鍵字,不能使用 select from tbstudent where stuaddress isnull 查詢籍貫不是null的所有同學 select from tbstudent where s...