Commit 87a77eec authored by Alexey Botchkov's avatar Alexey Botchkov

Bug#38083 Error-causing row inserted into partitioned table despite error

      
    problems are located in the sql_partition.cc where functions calculation
    partition_id don't expect error returned from item->val_int().
    Fixed by adding checks to these functions.
    Note  - it tries to fix more problems than just the reported bug.
      
per-file comments:
modified:
  mysql-test/r/partition.result
    Bug#38083 Error-causing row inserted into partitioned table despite error
        test result
  mysql-test/t/partition.test
    Bug#38083 Error-causing row inserted into partitioned table despite error
        test case
  sql/opt_range.cc
    Bug#38083 Error-causing row inserted into partitioned table despite error
        get_part_id() call fixed
  sql/partition_info.h
    Bug#38083 Error-causing row inserted into partitioned table despite error
        get_subpart_id_func interface changed. 
  sql/sql_partition.cc
    Bug#38083 Error-causing row inserted into partitioned table despite error
        various functions calculationg partition_id and subpart_id didn't expect
            an error returned from item->val_int().  Error checks added.
parent 0d380151
......@@ -1637,4 +1637,23 @@ select count(*) from t1, t2 where t1.createdDate = t2.createdDate;
count(*)
1
drop table t1, t2;
SET @orig_sql_mode = @@SQL_MODE;
SET SQL_MODE='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
CREATE TABLE t1 (c1 INT)
PARTITION BY LIST(1 DIV c1) (
PARTITION p0 VALUES IN (NULL),
PARTITION p1 VALUES IN (1)
);
INSERT INTO t1 VALUES (0);
ERROR 22012: Division by 0
SELECT * FROM t1;
c1
TRUNCATE t1;
INSERT INTO t1 VALUES (NULL), (0), (1), (2);
ERROR 22012: Division by 0
SELECT * FROM t1;
c1
NULL
DROP TABLE t1;
SET SQL_MODE= @orig_sql_mode;
End of 5.1 tests
......@@ -1791,4 +1791,27 @@ select count(*) from t1, t2 where t1.createdDate = t2.createdDate;
drop table t1, t2;
#
# Bug #38083 Error-causing row inserted into partitioned table despite error
#
SET @orig_sql_mode = @@SQL_MODE;
SET SQL_MODE='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
CREATE TABLE t1 (c1 INT)
PARTITION BY LIST(1 DIV c1) (
PARTITION p0 VALUES IN (NULL),
PARTITION p1 VALUES IN (1)
);
-- error ER_DIVISION_BY_ZERO
INSERT INTO t1 VALUES (0);
SELECT * FROM t1;
TRUNCATE t1;
-- error ER_DIVISION_BY_ZERO
INSERT INTO t1 VALUES (NULL), (0), (1), (2);
SELECT * FROM t1;
DROP TABLE t1;
SET SQL_MODE= @orig_sql_mode;
--echo End of 5.1 tests
......@@ -3215,10 +3215,12 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree)
ppar->subpart_fields););
/* Find the subpartition (it's HASH/KEY so we always have one) */
partition_info *part_info= ppar->part_info;
uint32 subpart_id= part_info->get_subpartition_id(part_info);
uint32 part_id, subpart_id;
if (part_info->get_subpartition_id(part_info, &subpart_id))
return 0;
/* Mark this partition as used in each subpartition. */
uint32 part_id;
while ((part_id= ppar->part_iter.get_next(&ppar->part_iter)) !=
NOT_A_PARTITION_ID)
{
......
......@@ -25,8 +25,9 @@ class partition_info;
typedef int (*get_part_id_func)(partition_info *part_info,
uint32 *part_id,
longlong *func_value);
typedef uint32 (*get_subpart_id_func)(partition_info *part_info);
typedef int (*get_subpart_id_func)(partition_info *part_info,
uint32 *part_id);
struct st_ddl_log_memory_entry;
class partition_info : public Sql_alloc
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment