[MDEV-10075] Provide index of error causing error in array INSERT Created: 2016-05-16 Updated: 2023-03-21 Due: 2021-09-14 Resolved: 2021-10-26 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Admin statements |
| Fix Version/s: | 10.7.1 |
| Type: | Task | Priority: | Blocker |
| Reporter: | Anders Karlsson | Assignee: | Rucha Deodhar |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
When executing a multi-row INSERT using array notation, i.e.:
If there is an error in this statement for example a PRIMARY KEY error, then there is no way of knowing which element in the array caused the error. This really limits the usefulness of array INSERTs which is an issue as this is a really good way to increase INSERT performance. The suggestion is to add the ability to find the index of the value with an issue by adding a new function to the API. This also need to be made available through Stored Procedures so maybe it should be complemented with a SQL-function. In addition, one such function will also be necessary, for the same reason, for prepared statements. |
| Comments |
| Comment by Anders Karlsson [ 2016-05-19 ] | ||||||||||||||||||||||||||||||
|
I have had a closer look at what an implementation could look like. A API function might not be necessary or even desired, rather a SQL function should work well and this has the advantage of being accessible independent of the client. I created an experimental patch for this, where I added a variable for the index of the current and previous statement to Diagnostics_area in sql_error.h, set this in write_record in sql_insert.cc and then a SQL function to return the value of the previous statement value in item_func.cc and item_create.cc. There is more to it than this for a complete implementation, if for no other reason so because I'm don't know the MariaDB source code that well anymore, but this is enough to prove that this works, which it does:
| ||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-05-29 ] | ||||||||||||||||||||||||||||||
|
I'd say, it'll be more consistent with the current implementation to use GET DIAGNOSTICS:
Similarly we can implement
| ||||||||||||||||||||||||||||||
| Comment by Rucha Deodhar [ 2021-08-16 ] | ||||||||||||||||||||||||||||||
|
Patch: | ||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2021-09-08 ] | ||||||||||||||||||||||||||||||
|
All is OK, just fix 2 things I mentioned about test suite. | ||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-09-14 ] | ||||||||||||||||||||||||||||||
|
Is there a reason this row number cannot be a part of the error message itself (in addition to diagnostics property)?
While diagnostics property is useful to detect the number of the flawed row programmatically, in interactive execution having it in the error text is clearly more user-friendly, especially when many values are involved:
| ||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-09-14 ] | ||||||||||||||||||||||||||||||
|
A note unrelated to the previous one
If something is an "index" here, it's the condition number (1), but the failing row number is 2. And it's a warning. | ||||||||||||||||||||||||||||||
| Comment by Rucha Deodhar [ 2021-09-14 ] | ||||||||||||||||||||||||||||||
|
Hi elenst , Error messages are not very specific for every statement. Example we can have Data truncated for col 'a' at row i for ALTER too and not just INSERT. Plus not all error messages reflect which row gave error or warning. ERROR_INDEX works only for INSERT and also makes it possible to know which row has problem for all INSERT-related errors/warnings. ROW_NUMBER looked a little non-specific to me, so I named it ERROR_INDEX from the task title. I agree it isn't really an "index", but it indicates the i-th row, so it made sense to start from 1 instead of 0. (But I can change it if it is not too late, the closer it is to its actual function the better). It seemed better to also have warning along with errors if there are problematic rows especially in case of INSERT...IGNORE where errors are ignored but user might still want to know the row that gave warning. | ||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2021-09-15 ] | ||||||||||||||||||||||||||||||
|
This issue was closed too early, before all comments were addressed. So they were moved to separate, linked, issues. | ||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2021-10-16 ] | ||||||||||||||||||||||||||||||
|
let's keep it open until bb-10.7-row_number is pushed | ||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-10-21 ] | ||||||||||||||||||||||||||||||
|
In my opinion the functionality as of bb-10.7-row_number d555ae3 can be merged into 10.7 main branch and released with 10.7.1. It is not perfect due to inherited legacy issues, but
There will be a fair amount of wrong or questionable results for SQL statements which weren't the target of this task. Some are already reported as bugs, and there are more to come. In many cases it is not even obvious what the result should be. I expect that depending on the feedback we will be able to determine whether the functionality is employed by a sufficient part of users, and if it is, in future releases it will be adjusted to a more predictable behavior with a wider range of statements. |