[MDEV-19761] Before Trigger not processed for Not Null Columns Created: 2019-06-14 Updated: 2023-11-28 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Update |
| Affects Version/s: | 10.1, 10.3.15, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10 |
| Fix Version/s: | 10.4, 10.5, 10.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | langfingaz | Assignee: | Anel Husakovic |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | upstream-fixed | ||
| Environment: |
Official MariaDB Docker Image (MARIADB_VERSION=1:10.3.15+maria~bionic) |
||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
Bug description: When inserting a new row into a table without specifying a column that is set to not null will give the error "Field 'xxx' doesn't have a default value" - even if a trigger exists, that should replace the NULL value with a not-null value before inserting it. Expected behavior: Triggers declared as "before insert on 'table_xxx' " should be fired if they might change any of the new values to insert BEFORE column constrains are verified. See similar SQL bug that has been fixed:
Actual behavior: If a new row contains a null value for a column that is defined as not null but is changed in a trigger, that trigger won't be fired at all as immediately a error is thrown. Example SQL code to reproduce the error:
Workaround:
Example SQL code to demonstrate the workaround: (Note: Only the insert statement as well as the comparison in the trigger (if new.rate is null) changed.)
|
| Comments |
| Comment by Alice Sherepa [ 2019-06-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks a lot! I reproduced on 10.1-10.4:
Mysql 8.0.15
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Anel Husakovic [ 2019-06-26 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi serg, Debugging codebase Debugging code base in `10.1`:
Observations
Observations b) switch_to_nullable_trigger_fields(fields, table)(2) called from mysql_insert():911
Notes *Note 1*: meaning of flags can be seen from (11)
*Note 2*: warnings are comming from `has_no_default_value()` (10)
*Note 3*: In case of nullable field `null_bit` is set to i-th bit of the i-th position of field in field_list. *Note 4*: Only test I have found with embedded server is `funcs_1.is_triggers_embedded ` and is skipped
Patch Patch: bb-anel-MDEV-19761 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-07-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I don't understand. What is the reason for the bug? What is your commit trying to do? In particular, this loop looks suspicious:
because you don't use f inside the loop and you don't change cnt inside the loop. |