~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/sysdate_local.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:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
22
#include <drizzled/function/time/sysdate_local.h>
23
23
#include <drizzled/tztime.h>
27
27
{
28
28
 
29
29
/**
30
 
    Converts current time in time_t to type::Time represenatation for local
 
30
    Converts current time in time_t to DRIZZLE_TIME represenatation for local
31
31
    time zone. Defines time zone (local) used for whole SYSDATE function.
32
32
*/
33
 
void Item_func_sysdate_local::store_now_in_TIME(type::Time &now_time)
 
33
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
34
34
{
35
 
  getSession().variables.time_zone->gmt_sec_to_TIME(now_time, time(NULL));
 
35
  Session *session= current_session;
 
36
  session->variables.time_zone->gmt_sec_to_TIME(now_time, time(NULL));
36
37
}
37
38
 
38
39
 
39
40
String *Item_func_sysdate_local::val_str(String *)
40
41
{
41
42
  assert(fixed == 1);
42
 
  store_now_in_TIME(ltime);
43
 
 
44
 
  size_t length= type::Time::MAX_STRING_LENGTH;
45
 
  ltime.convert(buff, length);
46
 
  buff_length= length;
47
 
  str_value.set(buff, length, &my_charset_bin);
48
 
 
 
43
  store_now_in_TIME(&ltime);
 
44
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
 
45
  str_value.set(buff, buff_length, &my_charset_bin);
49
46
  return &str_value;
50
47
}
51
48
 
53
50
int64_t Item_func_sysdate_local::val_int()
54
51
{
55
52
  assert(fixed == 1);
56
 
  store_now_in_TIME(ltime);
57
 
  int64_t tmp;
58
 
  ltime.convert(tmp);
59
 
 
60
 
  return tmp;
 
53
  store_now_in_TIME(&ltime);
 
54
  return (int64_t) TIME_to_uint64_t_datetime(&ltime);
61
55
}
62
56
 
63
57
double Item_func_sysdate_local::val_real()
64
58
{
65
59
  assert(fixed == 1);
66
 
 
67
 
  store_now_in_TIME(ltime);
68
 
  int64_t tmp;
69
 
  ltime.convert(tmp);
70
 
 
71
 
  return int64_t2double(tmp);
 
60
  store_now_in_TIME(&ltime);
 
61
  return uint64_t2double(TIME_to_uint64_t_datetime(&ltime));
72
62
}
73
63
 
74
64
 
80
70
}
81
71
 
82
72
 
83
 
bool Item_func_sysdate_local::get_date(type::Time &res, uint32_t )
 
73
bool Item_func_sysdate_local::get_date(DRIZZLE_TIME *res,
 
74
                                       uint32_t )
84
75
{
85
 
  store_now_in_TIME(ltime);
86
 
  res= ltime;
 
76
  store_now_in_TIME(&ltime);
 
77
  *res= ltime;
87
78
  return 0;
88
79
}
89
80
 
90
81
 
91
82
int Item_func_sysdate_local::save_in_field(Field *to, bool )
92
83
{
93
 
  store_now_in_TIME(ltime);
 
84
  store_now_in_TIME(&ltime);
94
85
  to->set_notnull();
95
 
  to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
96
 
 
 
86
  to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
97
87
  return 0;
98
88
}
99
89