I'm afraid that CONDITION_INDEX would be entirely misleading though. What is most likely thought as a condition index is the number which goes after the CONDITION word in GET DIAGNOSTICS statement, and it's very different from the value which is currently implemented as ERROR_INDEX. Please consider the example:
MariaDB [test]> create table t (pk int primary key, a char(3), check(a is not null));
|
Query OK, 0 rows affected (0.025 sec)
|
|
MariaDB [test]> insert into t values (1,'foo'),(2,'bar');
|
Query OK, 2 rows affected (0.006 sec)
|
Records: 2 Duplicates: 0 Warnings: 0
|
|
MariaDB [test]> insert ignore into t values (3,'qux'),(1,'foo'),(2,null),(2,'foobar');
|
Query OK, 1 row affected, 4 warnings (0.004 sec)
|
Records: 3 Duplicates: 2 Warnings: 4
|
So, at this point we have 4 conditions:
MariaDB [test]> show warnings;
|
+---------+------+-------------------------------------------------+
|
| Level | Code | Message |
|
+---------+------+-------------------------------------------------+
|
| Warning | 1062 | Duplicate entry '1' for key 'PRIMARY' |
|
| Warning | 4025 | CONSTRAINT `CONSTRAINT_1` failed for `test`.`t` |
|
| Warning | 1265 | Data truncated for column 'a' at row 3 |
|
| Warning | 1062 | Duplicate entry '2' for key 'PRIMARY' |
|
+---------+------+-------------------------------------------------+
|
4 rows in set (0.001 sec)
|
For the condition no. 1, the value in question is 2 (2nd row in the VALUES list violates the PK constraint). And for all other conditions, no. 2-4, the value in question is 3 (3rd row in the VALUES list violates the PK restriction, the CHECK constraint, and exceeds the char length):
MariaDB [test]> get diagnostics condition 1 @n1 = error_index;
|
Query OK, 0 rows affected (0.001 sec)
|
|
MariaDB [test]> get diagnostics condition 2 @n2 = error_index;
|
Query OK, 0 rows affected (0.001 sec)
|
|
MariaDB [test]> get diagnostics condition 3 @n3 = error_index;
|
Query OK, 0 rows affected (0.001 sec)
|
|
MariaDB [test]> get diagnostics condition 4 @n4 = error_index;
|
Query OK, 0 rows affected (0.001 sec)
|
|
MariaDB [test]> select @n1, @n2, @n3, @n4;
|
+------+------+------+------+
|
| @n1 | @n2 | @n3 | @n4 |
|
+------+------+------+------+
|
| 2 | 3 | 3 | 3 |
|
+------+------+------+------+
|
1 row in set (0.001 sec)
|
So, only n3 value coincides with the condition index, and it is indeed a pure coincidence. In reality it will rarely happen, it will be as uncorrelated as this:
MariaDB [test]> create table t (pk int primary key);
|
Query OK, 0 rows affected (0.029 sec)
|
|
MariaDB [test]> insert into t values (20);
|
Query OK, 1 row affected (0.006 sec)
|
|
MariaDB [test]> insert into t select seq from seq_5_to_50;
|
ERROR 1062 (23000): Duplicate entry '20' for key 'PRIMARY'
|
MariaDB [test]> show warnings;
|
+-------+------+----------------------------------------+
|
| Level | Code | Message |
|
+-------+------+----------------------------------------+
|
| Error | 1062 | Duplicate entry '20' for key 'PRIMARY' |
|
+-------+------+----------------------------------------+
|
1 row in set (0.000 sec)
|
|
MariaDB [test]> get diagnostics condition 1 @n1 = error_index;
|
Query OK, 0 rows affected (0.001 sec)
|
|
MariaDB [test]> select @n1;
|
+------+
|
| @n1 |
|
+------+
|
| 16 |
|
+------+
|
1 row in set (0.000 sec)
|
So, the condition index is 1, the violating PK value is 20, and the property value in question is 16.
Hi elenst , I could change it to ROW_NUMBER since it is more intuitive.