~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/drop_index.cc

  • Committer: Stewart Smith
  • Date: 2010-08-12 16:48:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: stewart@flamingspork.com-20100812164846-s9bhy47g60bvqs41
bug lp:611379 Equivalent queries with Impossible where return different results

The following two equivalent queries return different results in maria 5.2 and 5.3 (and identical results in mysql 5.5.5) :

SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` ;

SELECT * FROM ( SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` );

MariaDB returns 0 on the second query and NULL on the first, whereas MySQL returns NULL on both. In MariaDB, both EXPLAIN plans agree that "Impossible WHERE noticed after reading const tables"



We have some slightly different output in drizzle:

main.bug_lp611379 [ fail ]
drizzletest: At line 9: query 'explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a)
as t' failed: 1048: Column 'sum(distinct t1.a)' cannot be null

but the fix gets us the correct query results, although with slightly different execution plans.



This fix is directly ported from MariaDB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
  TableList *all_tables= session->lex->query_tables;
35
35
 
36
36
  /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
37
 
  message::table::shared_ptr original_table_message;
 
37
  message::Table original_table_message;
38
38
  {
39
 
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
 
39
    TableIdentifier identifier(first_table->db, first_table->table_name);
40
40
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
41
41
    {
42
 
      std::string path;
43
 
      identifier.getSQLPath(path);
44
 
      my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
 
42
      my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
45
43
      return true;
46
44
    }
47
45
  }
67
65
  create_info.db_type= 0;
68
66
 
69
67
  bool res;
70
 
  if (original_table_message->type() == message::Table::STANDARD )
 
68
  if (original_table_message.type() == message::Table::STANDARD )
71
69
  {
72
 
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
 
70
    TableIdentifier identifier(first_table->db, first_table->table_name);
73
71
 
74
72
    create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
75
73
 
77
75
                     identifier,
78
76
                     identifier,
79
77
                     &create_info, 
80
 
                     *original_table_message,
 
78
                     original_table_message,
81
79
                     create_table_proto, 
82
80
                     first_table,
83
81
                     &alter_info,
84
 
                     0, (Order*) 0, 0);
 
82
                     0, (order_st*) 0, 0);
85
83
  }
86
84
  else
87
85
  {
88
 
    TableIdentifier catch22(first_table->getSchemaName(), first_table->getTableName());
89
 
    Table *table= session->find_temporary_table(catch22);
 
86
    Table *table= session->find_temporary_table(first_table);
90
87
    assert(table);
91
88
    {
92
 
      TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName(), table->getShare()->getPath());
 
89
      TableIdentifier identifier(first_table->db, first_table->table_name, table->s->getPath());
93
90
      create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
94
91
 
95
92
      res= alter_table(session, 
96
93
                       identifier,
97
94
                       identifier,
98
95
                       &create_info, 
99
 
                       *original_table_message,
 
96
                       original_table_message,
100
97
                       create_table_proto, 
101
98
                       first_table,
102
99
                       &alter_info,
103
 
                       0, (Order*) 0, 0);
 
100
                       0, (order_st*) 0, 0);
104
101
    }
105
102
  }
106
103
  return res;