~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/heap_priv.h

  • 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
/* This file is included in all heap-files */
17
 
#ifndef PLUGIN_MEMORY_HEAP_PRIV_H
18
 
#define PLUGIN_MEMORY_HEAP_PRIV_H
 
17
#ifndef PLUGIN_HEAP_HEAP_PRIV_H
 
18
#define PLUGIN_HEAP_HEAP_PRIV_H
19
19
 
20
20
#include "config.h"
21
21
#include <drizzled/base.h>
52
52
#define hp_find_hash(A,B) ((HASH_INFO*) hp_find_block((A),(B)))
53
53
 
54
54
        /* Find pos for record and update it in info->current_ptr */
55
 
#define hp_find_record(info,pos) (info)->current_ptr= hp_find_block(&(info)->getShare()->recordspace.block,pos)
 
55
#define hp_find_record(info,pos) (info)->current_ptr= hp_find_block(&(info)->s->recordspace.block,pos)
56
56
 
57
57
#define get_chunk_status(info,ptr) (ptr[(info)->offset_status])
58
58
 
64
64
  unsigned char *ptr_to_rec;
65
65
} HASH_INFO;
66
66
 
 
67
typedef struct {
 
68
  HA_KEYSEG *keyseg;
 
69
  uint32_t key_length;
 
70
  uint32_t search_flag;
 
71
} heap_rb_param;
 
72
 
67
73
        /* Prototypes for intern functions */
68
74
 
69
75
extern HP_SHARE *hp_find_named_heap(const char *name);
72
78
extern int hp_get_new_block(HP_BLOCK *info, size_t* alloc_length);
73
79
extern void hp_free(HP_SHARE *info);
74
80
extern unsigned char *hp_free_level(HP_BLOCK *block,uint32_t level,HP_PTRS *pos,
75
 
                                    unsigned char *last_pos);
 
81
                           unsigned char *last_pos);
76
82
extern int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
77
83
                        const unsigned char *record, unsigned char *recpos);
 
84
extern int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
 
85
                           const unsigned char *record, unsigned char *recpos);
 
86
extern int hp_rb_delete_key(HP_INFO *info,HP_KEYDEF *keyinfo,
 
87
                            const unsigned char *record,unsigned char *recpos,int flag);
78
88
extern int hp_delete_key(HP_INFO *info,HP_KEYDEF *keyinfo,
79
89
                         const unsigned char *record,unsigned char *recpos,int flag);
80
90
extern HASH_INFO *_heap_find_hash(HP_BLOCK *block,uint32_t pos);
90
100
                          const unsigned char *rec2,
91
101
                          bool diff_if_only_endspace_difference);
92
102
extern void hp_make_key(HP_KEYDEF *keydef,unsigned char *key,const unsigned char *rec);
 
103
extern uint32_t hp_rb_make_key(HP_KEYDEF *keydef, unsigned char *key,
 
104
                           const unsigned char *rec, unsigned char *recpos);
 
105
extern uint32_t hp_rb_key_length(HP_KEYDEF *keydef, const unsigned char *key);
 
106
extern uint32_t hp_rb_null_key_length(HP_KEYDEF *keydef, const unsigned char *key);
 
107
extern uint32_t hp_rb_var_key_length(HP_KEYDEF *keydef, const unsigned char *key);
93
108
extern bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const unsigned char *record);
94
109
extern int hp_close(HP_INFO *info);
95
110
extern void hp_clear(HP_SHARE *info);
 
111
extern uint32_t hp_rb_pack_key(HP_KEYDEF *keydef,
 
112
                               unsigned char *key, const unsigned char *old,
 
113
                               drizzled::key_part_map keypart_map);
96
114
 
97
115
   /* Chunkset management (alloc/free/encode/decode) functions */
98
116
 
99
117
extern unsigned char *hp_allocate_chunkset(HP_DATASPACE *info, uint32_t chunk_count);
 
118
extern int hp_reallocate_chunkset(HP_DATASPACE *info, uint32_t chunk_count, unsigned char* pos);
100
119
extern void hp_free_chunks(HP_DATASPACE *info, unsigned char *pos);
101
120
extern void hp_clear_dataspace(HP_DATASPACE *info);
102
121
 
103
122
extern uint32_t hp_get_encoded_data_length(HP_SHARE *info, const unsigned char *record, uint32_t *chunk_count);
104
123
extern void hp_copy_record_data_to_chunkset(HP_SHARE *info, const unsigned char *record, unsigned char *pos);
105
124
extern void hp_extract_record(HP_SHARE *info, unsigned char *record, const unsigned char *pos);
106
 
extern bool hp_compare_record_data_to_chunkset(HP_SHARE *info, const unsigned char *record, unsigned char *pos);
 
125
extern uint32_t hp_process_record_data_to_chunkset(HP_SHARE *info, const unsigned char *record, unsigned char *pos, uint32_t is_compare);
107
126
 
108
127
extern boost::mutex THR_LOCK_heap;
109
128
 
110
 
#endif /* PLUGIN_MEMORY_HEAP_PRIV_H */
 
129
#endif /* PLUGIN_HEAP_HEAP_PRIV_H */