[MDEV-20354] All but last insert ignored in InnoDB tables when table locked Created: 2019-08-15 Updated: 2020-12-08 Resolved: 2019-10-30 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Insert, Locking |
| Affects Version/s: | 10.1, 10.4.6, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.2.28, 10.1.42, 10.3.19, 10.4.9 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | William Turrell | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | insert, lock | ||
| Environment: |
macOS High Sierra 10.13.6, homebrew install stable 10.4.6 (bottled), mysql --version: mysql Ver 15.1 Distrib 10.4.6-MariaDB, for osx10.13 (x86_64) using readline 5.1 |
||
| Attachments: |
|
||||||||||||
| Issue Links: |
|
||||||||||||
| Description |
|
It's common when doing bulk inserts (e.g. when importing an SQL dump) for the table to be locked first. Whenever this happens, apparently only on InnoDB tables, all but the final insert is being ignored.
Here's a demo using a standard WordPress database structure from one table, and three demo rows. Expected: 3 rows for users foo, bar and baz Observed - single row - the last one baz. $ mysql mariadb_bug
I can confirm that if the inserts are batched, the last batch (of however many rows were in the insert statement) is retained. If can also confirm the same behaviour if I run the commands manually in SQL, one at at a time, rather than piping the SQL dump in - the table has 3 rows if I omit the lock and unlock statements, but only one if I include them. Multiple people are experiencing this with Drupal installations (either fresh installs, or when clearing the cache, which repopulates the Symfony routing table). When testing in_ MySQL_ (installed via homebrew or other means) in the same environment, rather than mariadb, the bug doesn't appear. It's possible this began in an earlier version than 10.4.6 (someone mentioned 10.4.4 on the above Drupal issue). I looked at the release notes for 10.4.7 (not available on Homebrew yet) and didn't spot anything related. |
| Comments |
| Comment by Alice Sherepa [ 2019-08-15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Could you please add your .cnf file(s).
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by William Turrell [ 2019-08-15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Alice, thanks for looking. Here's the full output of 'SHOW VARIABLES': variables.txt I don't seem to have any meaningful .cnf settings: according to this StackOverflow answer, there's no default config for Homebrew mysql (and, I assume, therefore, mariadb). I get this if I run mariadb --help "Default options are read from the following files in the given order: I all have in the former is:
and all I have in the latter (my home directory) is:
There's some Homebrew files here: /usr/local/Cellar/mariadb/10.4.6/.bottle/etc/my.cnf but there's nothing in those other than 'bind-address', and an instruction to include the other files/directory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2019-08-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I could not repeat, tried also on OS X 10.14.6, MariaDB 10.4.6, fresh installation by brew:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-08-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Could you please copy-paste your script contents (followed by the final select of course) into the client and provide complete unabridged output from it, like alice did above, only starting from the very beginning, DROP TABLE IF EXISTS etc.? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by William Turrell [ 2019-08-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@Elena Stepanova - done, see below.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by William Turrell [ 2019-08-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
So I can't reproduce it on macOS 10.14 (Mojave) either (that's the same build version as Alice). I've diffed the SHOW VARIABLES output between the two machines - there's nothing obvious, just different character set / logfile locations, pids, random seeds etc. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Sypes [ 2019-08-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have reproduced this issue on Mojave (v10.14.6) Since it was questioned earlier, I have attached my `my.conf` and `my.conf.d files`. my.cnf | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by John Ridgway [ 2019-09-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have reproduced this issue on CentOS 7 with MariaDB 10.4.7. In order to get all of the INSERTs to take effect I must not lock the table, and I must use autocommit (or commit after each INSERT). [ridgway@localhost host-migration]$ uname -a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by William Turrell [ 2019-09-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@John Ridgway thanks, someone else had problems with Drupal on CentOS 7, but when I tested it on a clean virtual server I couldn't reproduce it, either with the default mariadb version or one from http://archive.mariadb.org/ - would you be able to confirm the source of the package you're using? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by John Ridgway [ 2019-09-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
From the end of "yum install mariadb-server mariadb-client" (the rest had scrolled off the terminal): Installed: Dependency Installed: Replaced: The contents of the file /etc/yum.repos.d/MariaDB.repo are: [mariadb] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-09-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
By any chance, would it be possible to give a temporary access to our developer to your CentOS where the problem is reproducible? If not, could you please repeat the exercise from mariadb-insertion-bug-demo.sql | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Eugene Kazakov [ 2019-10-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem is producible on CentOS 7 after an upgrade of the MariaDB-server package from 5.5.64 (from the base repo) to 10.4.8 (from the MariaDB repo). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-10-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ekazakov: That's great, thanks. I'll email you for the details. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-10-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem occurs as described if the server is missing one (or all) of statistical tables mysql.table_stats, mysql.index_stats, mysql.column_stats. The most likely reason for the missing tables is that the instance was upgraded from MariaDB 5.5 (as it was in Eugene's case), or crossgraded from MySQL or Percona server, and mysql_upgrade was not run or did not succeed. You might not even be aware that the instance had an old server before, especially if it's installed as a part of another product, which might be why nobody mentioned it before. RPM-based systems don't run mysql_upgrade automatically upon installation, and probably Mac packages don't either. If mysql_upgrade wasn't run, the server is likely to complain upon startup in the error log about a wrong structure of mysql.event table and some other missing tables (but not about the tables which actually cause the failure). However, on package installations the error log is typically written to /var/log/messages or /var/log/syslog, so errors are easy to miss. Another symptom is the error message
In the scenario which reporters complained about, it is written to the error log upon UNLOCK TABLES execution. Anyone who experiences it (wturrell, msypes, jridgway@commongood.earth, ekazakov, and those who didn't comment) – could you please check whether you are missing any of mysql.table_stats, mysql.index_stats, mysql.column_stats, and if you do, run mysql_upgrade on the instance (use --force option if it refuses to run otherwise) and then check whether the problem disappears. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-10-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
MTR test case which (artificially) represents the use case described above by removing one of stat tables:
The problem is reproducible on all 10.x with engine-independent statistics enabled, but it is mainly observed on 10.4 because on 10.4 the EITS is enabled by default. Similar with START TRANSACTION instead of LOCK TABLE (this variation was earlier reported at stackoverflow:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergey Vojtovich [ 2019-10-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Blocker because incorrect results after upgrade to 10.4 where EITS is enabled by default. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Sypes [ 2019-10-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have none of the tables mentioned, neither mysql.table_stats, mysql.index_stats, nor mysql.column_stats. The closest I see are mysql.columns_priv and mysql.tables_priv. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-10-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sorry. Yes, if the tables don't exist, please run mysql_upgrade. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Sypes [ 2019-10-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ran mysql_upgrade. Lots of information spit out and I now see the *_stats tables. Of the three sites that displayed issues as a result, two appear to functioning normally again. The third I likely broke in other ways during my attempts to deal with the issue when it first occurred, so you can mark me down as saying that the fix works. Thanks! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Sypes [ 2019-10-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I don't know if this is related, but while poking around my instance to see if it's safe to use, I noticed that Sequel Pro can't see all the users and privileges, and also tends to crap out when trying to view them. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by William Turrell [ 2019-11-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello again.
Thanks, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Sypes [ 2019-11-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I've done some research on the Sequel Pro issue, and determined that it's unrelated to this this, but is a known issue, that's just new to me: |