Bug #21774 Column count doesn't match value count at row x
Submitted: 22 Aug 2006 8:46 Modified: 13 Sep 2006 17:31
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.24 OS:Any (*)
Assigned to: Timour Katchaounov

[22 Aug 2006 8:46] Shane Bester
Description:
Query that worked on 5.0.22 stops working on 5.0.24, with error message:

ERROR 1136 (21S01): Column count doesn't match value count at row 1

5.0.22:
....
mysql> INSERT IGNORE INTO db2.tbl2 SELECT tbl2.* FROM db1.tbl2;
Query OK, 0 rows affected (0.30 sec)
Records: 0  Duplicates: 0  Warnings: 0

5.0.24:
.....
mysql> INSERT IGNORE INTO db2.tbl2 SELECT tbl2.* FROM db1.tbl2;
ERROR 1136 (21S01): Column count doesn't match value count at row 1

How to repeat:
DROP DATABASE IF EXISTS db1;
DROP DATABASE IF EXISTS db2;
CREATE DATABASE db1;
CREATE DATABASE db2;
CREATE TABLE db1.tbl2(id VARCHAR(10) NOT NULL,label VARCHAR(255));
CREATE TABLE db2.tbl2(id VARCHAR(10) NOT NULL,label VARCHAR(255));
INSERT IGNORE INTO db2.tbl2 SELECT tbl2.* FROM db1.tbl2;

Suggested fix:
Workaround is to use:

INSERT IGNORE INTO db2.tbl2 SELECT db1.tbl2.* FROM db1.tbl2;
[11 Sep 2006 9:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11679

ChangeSet@1.2260, 2006-09-11 12:26:17+03:00, timour@lamia.home +5 -0
  Fix for BUG#21774: Column count doesn't match value count at row x
  
  Also completes the fix of related BUG 18080, because the fix for
  BUG#21774 exposed a problem with the fix for 18080.
  
  The problem was in that the handling of SQLCOM_INSERT in sql_parse.cc
  incorrectly and prematurely reset the name resolution context.
  In addition, setup_tables() also uncoditionally reset the name
  resolution context after processing NATURAL/USING joins.
  
  The fix removes unneccessary resets of the name resolution context.
[12 Sep 2006 11:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11761

ChangeSet@1.2254, 2006-09-12 14:33:14+03:00, timour@lamia.home +5 -0
  Fix for BUG#21774: Column count doesn't match value count at row x
  
  The cause of the bug was an incomplete fix for bug 18080.
  The problem was that setup_tables() unconditionally reset the
  name resolution context to its 'tables' argument, which pointed
  to the first table of an SQL statement.
  
  The bug fix limits resetting of the name resolution context in
  setup_tables() only in the cases when the context was not set
  by earlier parser/optimizer phases.
[12 Sep 2006 14:50] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11785

ChangeSet@1.2254, 2006-09-12 17:50:24+03:00, timour@lamia.home +5 -0
  Fix for BUG#21774: Column count doesn't match value count at row x
  
  The cause of the bug was an incomplete fix for bug 18080.
  The problem was that setup_tables() unconditionally reset the
  name resolution context to its 'tables' argument, which pointed
  to the first table of an SQL statement.
  
  The bug fix limits resetting of the name resolution context in
  setup_tables() only in the cases when the context was not set
  by earlier parser/optimizer phases.
[12 Sep 2006 15:47] Timour Katchaounov
Pushed into 5.0.25.
[12 Sep 2006 15:50] Mads Martin Joergensen
Our cloned 5.0.25. It's not yet in 5.0-main, so please put back to patch pending for 5.0 and 5.1 trees to get is pushed.
[12 Sep 2006 19:45] Paul Dubois
Noted in 5.0.25 changelog.

INSERT ... SELECT sometimes generated a spurious Column count doesn't
match value count error.

Resetting report to NDI pending merge into 5.1
[13 Sep 2006 14:57] Timour Katchaounov
Pushed into main trees - 5.0.26 and 5.1.12.
[13 Sep 2006 17:31] Paul Dubois
Noted in 5.1.12 changelog.