~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/linebuffer.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:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* readline for batch mode */
17
17
 
18
 
#include <config.h>
19
 
#include <drizzled/internal/my_sys.h>
20
 
#include <client/linebuffer.h>
21
 
#include <boost/version.hpp>
 
18
#include "config.h"
 
19
#include "drizzled/internal/my_sys.h"
 
20
#include "client/linebuffer.h"
22
21
 
23
22
#include <vector>
24
23
 
28
27
LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file)
29
28
  :
30
29
    file(my_file),
31
 
    max_size(my_max_size)
 
30
    line(),
 
31
    max_size(my_max_size),
 
32
    eof(false)
32
33
{
33
 
  if (my_file)
34
 
 
35
 
  /*
36
 
    if here beacuse the old way of using file_descriptor is deprecated in boost
37
 
    1.44.  There is a #define to re-enable the function but this is broken in
38
 
    Fedora 14. See https://bugzilla.redhat.com/show_bug.cgi?id=654480
39
 
  */
40
 
#if BOOST_VERSION < 104400
41
 
    file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), true);
42
 
#else
43
 
    file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), boost::iostreams::never_close_handle);
44
 
#endif
45
 
  else
46
 
    file_stream = new std::stringstream;
47
34
  line.reserve(max_size);
48
35
}
49
36
 
50
37
void LineBuffer::addString(const string &str)
51
38
{
52
 
  (*file_stream) << str << endl;
 
39
  buffer << str << endl;
53
40
}
54
41
 
55
42
char *LineBuffer::readline()
56
43
{
57
 
  file_stream->getline(&line[0], max_size);
58
 
 
59
 
  if (file_stream->fail())
 
44
  uint32_t read_count;
 
45
 
 
46
  if (file && !eof)
 
47
  {
 
48
    if ((read_count= read(fileno(file), (&line[0]), max_size-1)))
 
49
    {
 
50
      line[read_count+1]= '\0';
 
51
      buffer << &line[0];
 
52
    }
 
53
    else
 
54
      eof= true;
 
55
  }
 
56
 
 
57
  buffer.getline(&line[0],max_size);
 
58
 
 
59
  if (buffer.eof())
60
60
    return 0;
61
61
  else
62
62
    return &line[0];