Bug #40158 Falcon assertion in StorageInterface::encodeRecord() line 2635 on CREATE TABLE
Submitted: 19 Oct 2008 22:16 Modified: 13 Dec 2008 11:04
Reporter: Philip Stoev
Status: Closed
Category:Server: Falcon Severity:S1 (Critical)
Version:6.0-falcon-team OS:Any
Assigned to: Lars-Erik Bjørk Target Version:6.0.9
Tags: F_ENCODING
Triage: Triaged: D1 (Critical)

[19 Oct 2008 22:16] Philip Stoev
Description:
Falcon asserts like this:

[Falcon] Error: assertion (field) failed at line 2635 in file ha_falcon.cpp

with this stack:

#6  0x00584fe0 in raise () from /lib/libpthread.so.0
#7  0x0859c620 in Error::debugBreak () at Error.cpp:94
#8  0x0859c69d in Error::error (string=0x8988198 "assertion (%s) failed at line %d in
file %s\n") at Error.cpp:71
#9  0x0859c747 in Error::assertionFailed (text=0x897a867 "field", fileName=0x897a3c5
"ha_falcon.cpp", line=2635) at Error.cpp:78
#10 0x0852f530 in StorageInterface::encodeRecord (this=0xa567248, buf=0xa567410
"Ч\0011\b", updateFlag=false) at ha_falcon.cpp:2635
#11 0x085347c2 in StorageInterface::write_row (this=0xa567248, buff=0xa567410
"Ч\0011\b") at ha_falcon.cpp:1110
#12 0x083e4e5e in handler::ha_write_row (this=0xa567248, buf=0xa567410 "Ч\0011\b") at
handler.cc:5317
#13 0x08359d91 in write_record (thd=0xaea92480, table=0xa566b70, info=0xa572218) at
sql_insert.cc:1604
#14 0x0835a17d in select_insert::send_data (this=0xa5721f8, values=@0xaea93924) at
sql_insert.cc:3155
#15 0x083519f5 in JOIN::exec (this=0xa564308) at sql_select.cc:2303
#16 0x0834e578 in mysql_select (thd=0xaea92480, rref_pointer_array=0xaea93994,
tables=0x0, wild_num=0, fields=@0xaea93924, conds=0x0, og_num=0, order=0x0,
    group=0x0, having=0x0, proc_param=0x0, select_options=2416200192, result=0xa5721f8,
unit=0xaea935f8, select_lex=0xaea93890) at sql_select.cc:3017
#17 0x08353a7c in handle_select (thd=0xaea92480, lex=0xaea9359c, result=0xa5721f8,
setup_tables_done_option=0) at sql_select.cc:300
#18 0x082c774b in mysql_execute_command (thd=0xaea92480) at sql_parse.cc:2454
#19 0x082ceba8 in mysql_parse (thd=0xaea92480, inBuf=0xa571708 "create table t1
engine=falcon select if(1,'1','0'), month(\"2002-08-02\")", length=71,
    found_semicolon=0xa8db5e70) at sql_parse.cc:5587
#20 0x082cf5f2 in dispatch_command (command=COM_QUERY, thd=0xaea92480,
    packet=0xaeabac11 "create table t1 engine=falcon select if(1,'1','0'),
month(\"2002-08-02\")", packet_length=71) at sql_parse.cc:1002
#21 0x082d090f in do_command (thd=0xaea92480) at sql_parse.cc:689
#22 0x082bf0c3 in handle_one_connection (arg=0xaea92480) at sql_connect.cc:1153
#23 0x0057d32f in start_thread () from /lib/libpthread.so.0
#24 0x0049a27e in clone () from /lib/libc.so.6

2630                    {
2631                    if (fieldFormat->fieldId < 0 || fieldFormat->offset == 0)
2632                            continue;
2633
2634                    Field *field = fieldMap[fieldFormat->fieldId];
2635                    ASSERT(field); <<<<<<<<<<<<<<<<< HERE
2636
2637                    if (ptrDiff)
2638                            field->move_field_offset(ptrDiff);
2639

(gdb) print field
$1 = (class Field *) 0x0

How to repeat:
create table t1 engine=falcon select if(1,'1','0'), month("2002-08-02");
[29 Oct 2008 16:18] Kevin Lewis
Lars-Erik,  This bug hits the same ASSERT(field) as in

 Bug#39388: Falcon crashes when doing INSERT if column name in Falcon table contains ""

In this case, the problem is the double quotes in the assumed column name;
   month("2002-08-02")

If I change the create table statement to this, it works OK.
   create table t1 engine=falcon select if(1,'1','0'), month('2002-08-02');

StorageShare::cleanupFieldName() converts 
   month("2002-08-02")
to 
   month(""2002-08-02"")

From there, I am not sure why the column name is not accepted.  Since you looked at this
before, maybe you can figure it out.
[29 Oct 2008 16:21] Ann Harrison
The problem is the double quotes in the month expression

create table t1 engine=falcon select if(1,'1','0'), month("2002-08-02");

this statement works correctly:

create table t1 engine=falcon select if(1,'1','0'), month('2002-08-02');
[29 Oct 2008 19:07] Lars-Erik Bjørk
Just looking briefly at this, it does look like the same bug as bug#39388 (as Kevin
suggested).

The reason it fails (copied from the other bug report) is:

"In StorageInterface::mapFields, when populating the fieldMap, before we try to look up
the
fieldId, we
do:

storageShare->cleanupFieldName(field->field_name, nameBuffer,
sizeof(nameBuffer));

This does, for some reason, add an additional " for every " in the name,
turning the "clean" field name into ""name"". This doesn't match
with "name" when comparing before (not) inserting into the fieldMap." 

I will look at it more thoroughly tomorrow, but I reckon it can be closed as a
duplicate.

However, if it is the same bug, then they probably should have the same Triage and
priority?
[5 Nov 2008 11:30] 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/57866

2901 lars-erik.bjork@sun.com	2008-11-05
      This is a commit for bug#40158 
      (Falcon assertion in StorageInterface::encodeRecord() line 2635 on CREATE TABLE)
      
      The nature of this bug is explained earlier. 
      
      This patch adds a bool argument to StorageTableShare::cleanupFieldName
      telling if the function should double the number of quotes or not. So
      far, StorageInterface::mapFields, is the only place this method is
      called, passing 'false'. All other places it is called passing
      'true'. This will ensure that the parser still gets the expected
      number of quotes and we are able to look up the fields correctly.
      
      I have also added a regression test for this bug, creating - and
      inserting into - a table with a field name containing quotes.
[5 Nov 2008 13:30] 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/57878

2901 lars-erik.bjork@sun.com	2008-11-05
      This is a commit for bug#40158 
      (Falcon assertion in StorageInterface::encodeRecord() line 2635 on CREATE TABLE)
      
      The nature of this bug is explained earlier. 
      
      This patch adds a bool argument to StorageTableShare::cleanupFieldName
      telling if the function should double the number of quotes or not. So
      far, StorageInterface::mapFields, is the only place this method is
      called, passing 'false'. All other places it is called passing
      'true'. This will ensure that the parser still gets the expected
      number of quotes and we are able to look up the fields correctly.
      
      I have also added a regression test for this bug, creating - and
      inserting into - a table with a field name containing quotes.
[5 Nov 2008 13:42] 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/57882

2901 lars-erik.bjork@sun.com	2008-11-05
      This is a commit for bug#40158 
      (Falcon assertion in StorageInterface::encodeRecord() line 2635 on CREATE TABLE)
      
      The nature of this bug is explained earlier. 
      
      This patch adds a bool argument to StorageTableShare::cleanupFieldName
      telling if the function should double the number of quotes or not. So
      far, StorageInterface::mapFields, is the only place this method is
      called, passing 'false'. All other places it is called passing
      'true'. This will ensure that the parser still gets the expected
      number of quotes and we are able to look up the fields correctly.
      
      I have also added a regression test for this bug, creating - and
      inserting into - a table with a field name containing quotes.
      
      
      added mysql-test/suite/falcon/r/falcon_bug_40158.result
      -------------------------------------------------------
      Result file for the regression test
      
      
      
      added mysql-test/suite/falcon/t/falcon_bug_40158.test
      -----------------------------------------------------
      * Regression test, testing differently quoted field names
      
      modified storage/falcon/StorageTableShare.cpp
      ---------------------------------------------
      * Modified StorageTableShare::cleanupFieldName to handle the new
        argument.
      
      modified storage/falcon/StorageTableShare.h
      -------------------------------------------
      * Added  new argument to the signature of
        StorageTableShare::cleanupFieldName
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
      
      modified storage/falcon/ha_falcon.cpp
      -------------------------------------
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
[5 Nov 2008 13:44] 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/57883

2901 lars-erik.bjork@sun.com	2008-11-05
      This is a commit for bug#40158 
      (Falcon assertion in StorageInterface::encodeRecord() line 2635 on CREATE TABLE)
      
      The nature of this bug is explained earlier. 
      
      This patch adds a bool argument to StorageTableShare::cleanupFieldName
      telling if the function should double the number of quotes or not. So
      far, StorageInterface::mapFields, is the only place this method is
      called, passing 'false'. All other places it is called passing
      'true'. This will ensure that the parser still gets the expected
      number of quotes and we are able to look up the fields correctly.
      
      I have also added a regression test for this bug, creating - and
      inserting into - a table with a field name containing quotes.
      
      
      added mysql-test/suite/falcon/r/falcon_bug_40158.result
      -------------------------------------------------------
      Result file for the regression test
      
      
      
      added mysql-test/suite/falcon/t/falcon_bug_40158.test
      -----------------------------------------------------
      * Regression test, testing differently quoted field names
      
      modified storage/falcon/StorageTableShare.cpp
      ---------------------------------------------
      * Modified StorageTableShare::cleanupFieldName to handle the new
        argument.
      
      modified storage/falcon/StorageTableShare.h
      -------------------------------------------
      * Added  new argument to the signature of
        StorageTableShare::cleanupFieldName
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
      
      modified storage/falcon/ha_falcon.cpp
      -------------------------------------
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
[5 Nov 2008 13:49] 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/57885

2901 lars-erik.bjork@sun.com	2008-11-05
      This is a commit for bug#40158 
      (Falcon assertion in StorageInterface::encodeRecord() line 2635 on CREATE TABLE)
      
      The nature of this bug is explained earlier. 
      
      This patch adds a bool argument to StorageTableShare::cleanupFieldName
      telling if the function should double the number of quotes or not. So
      far, StorageInterface::mapFields, is the only place this method is
      called, passing 'false'. All other places it is called passing
      'true'. This will ensure that the parser still gets the expected
      number of quotes and we are able to look up the fields correctly.
      
      I have also added a regression test for this bug, creating - and
      inserting into - a table with a field name containing quotes.
      
      
      added mysql-test/suite/falcon/r/falcon_bug_40158.result
      -------------------------------------------------------
      Result file for the regression test
      
      
      
      added mysql-test/suite/falcon/t/falcon_bug_40158.test
      -----------------------------------------------------
      * Regression test, testing differently quoted field names
      
      modified storage/falcon/StorageTableShare.cpp
      ---------------------------------------------
      * Modified StorageTableShare::cleanupFieldName to handle the new
        argument.
      
      modified storage/falcon/StorageTableShare.h
      -------------------------------------------
      * Added  new argument to the signature of
        StorageTableShare::cleanupFieldName
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
      
      modified storage/falcon/ha_falcon.cpp
      -------------------------------------
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
[5 Nov 2008 15:52] 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/57897

2901 lars-erik.bjork@sun.com	2008-11-05
      This is a commit for bug#40158 
      (Falcon assertion in StorageInterface::encodeRecord() line 2635 on CREATE TABLE)
      
      The nature of this bug is explained earlier. 
      
      This patch adds a bool argument to StorageTableShare::cleanupFieldName
      telling if the function should double the number of quotes or not. So
      far, StorageInterface::mapFields, is the only place this method is
      called, passing 'false'. All other places it is called passing
      'true'. This will ensure that the parser still gets the expected
      number of quotes and we are able to look up the fields correctly.
      
      I have also added a regression test for this bug, creating - and
      inserting into - a table with a field name containing quotes.
      
      
      added mysql-test/suite/falcon/r/falcon_bug_40158.result
      -------------------------------------------------------
      Result file for the regression test
      
      
      
      added mysql-test/suite/falcon/t/falcon_bug_40158.test
      -----------------------------------------------------
      * Regression test, testing differently quoted field names
      
      modified storage/falcon/StorageTableShare.cpp
      ---------------------------------------------
      * Modified StorageTableShare::cleanupFieldName to handle the new
        argument.
      
      modified storage/falcon/StorageTableShare.h
      -------------------------------------------
      * Added  new argument to the signature of
        StorageTableShare::cleanupFieldName
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
      
      modified storage/falcon/ha_falcon.cpp
      -------------------------------------
      * Made sure that all usages of StorageTableShare::cleanupFieldName
        passes the new argument
[20 Nov 2008 13:55] Bugs System
Pushed into 6.0.8-alpha  (revid:lars-erik.bjork@sun.com-20081105145137-17o6ljadgbmucst0)
(version source revid:lars-erik.bjork@sun.com-20081105145137-17o6ljadgbmucst0) (pib:5)
[13 Dec 2008 11:04] MC Brown
A note has been added to the 6.0.8 changelog: 

Creating a table, or selecting from a table using the FALCON storage engine and with a
double quote in the name would cause an assertion failure.