~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/xt_defs.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:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * Author: Paul McCullagh
20
20
 *
478
478
 */
479
479
#define XT_XLOG_FLUSH_FREQ                              1000
480
480
 
481
 
/*
482
 
 * Define here if you want to check (and correct) the table free list
483
 
 * counts. The free list counts are not durable, because they are not
484
 
 * written to the log.
485
 
 *
486
 
 * The row free count is most critical because it can be used to
487
 
 * estimate the the of rows in the record.
488
 
 */
489
 
#define XT_CHECK_ROW_FREE_COUNT
490
 
#ifdef DEBUG
491
 
#define XT_CHECK_RECORD_FREE_COUNT
492
 
#endif
493
 
#define XT_CORRECT_TABLE_FREE_COUNT 
494
 
 
495
 
#if defined(XT_CHECK_ROW_FREE_COUNT) && defined(XT_CORRECT_TABLE_FREE_COUNT)
496
 
#define XT_ROW_COUNT_CORRECTED
497
 
#endif
498
 
 
499
481
/* ----------------------------------------------------------------------
500
482
 * GLOBAL CONSTANTS
501
483
 */
574
556
 */
575
557
 
576
558
/* Missing on some Solaris machines: */
577
 
/* Drizzle compiles with this stuff defined here.
578
 
 * Is there a reason why they should not go here?
579
 
 * In general, this should come after the system
580
 
 * headers, just in case they are defined in the 
581
 
 * system headers. xt_defs.h should be included
582
 
 * after the system headers. xt_config.h should be
583
 
 * included before the system headers.
584
 
 */
585
559
#ifndef BIG_ENDIAN
586
560
#define BIG_ENDIAN 4321
587
561
#endif
863
837
#define STRUCT_TABLE                                            class drizzled::TableShare
864
838
#define TABLE_SHARE                                                     TableShare
865
839
#define GET_TABLE_SHARE(x)                                      (x)
866
 
#define GET_TABLE_FIELDS(x)                                     ((x)->getFields(true))
 
840
#define GET_TABLE_FIELDS(x)                                     (&(x)->getFields()[0])
867
841
 
868
842
#define MYSQL_TYPE_STRING                                       DRIZZLE_TYPE_VARCHAR
869
843
#define MYSQL_TYPE_VARCHAR                                      DRIZZLE_TYPE_VARCHAR
872
846
#define MYSQL_TYPE_ENUM                                         DRIZZLE_TYPE_ENUM
873
847
#define MYSQL_TYPE_LONG                                         DRIZZLE_TYPE_LONG
874
848
#define MYSQL_PLUGIN_VAR_HEADER                         DRIZZLE_PLUGIN_VAR_HEADER
 
849
#define MYSQL_SYSVAR_STR                                        DRIZZLE_SYSVAR_STR
 
850
#define MYSQL_SYSVAR_INT                                        DRIZZLE_SYSVAR_INT
 
851
#define MYSQL_SYSVAR_BOOL                                       DRIZZLE_SYSVAR_BOOL
 
852
#define MYSQL_SYSVAR                                            DRIZZLE_SYSVAR
875
853
#define MYSQL_STORAGE_ENGINE_PLUGIN                     DRIZZLE_STORAGE_ENGINE_PLUGIN
876
854
#define MYSQL_INFORMATION_SCHEMA_PLUGIN         DRIZZLE_INFORMATION_SCHEMA_PLUGIN
877
855
#define memcpy_fixed                                            memcpy
888
866
#define MX_CHARSET_INFO                                         struct drizzled::charset_info_st
889
867
#define MX_CONST_CHARSET_INFO                           const struct drizzled::charset_info_st                  
890
868
#define MX_CONST                                                        const
891
 
#include <boost/dynamic_bitset.hpp>
892
 
#define MX_BITMAP                                                       boost::dynamic_bitset<>
893
 
#define MX_BIT_SIZE()                                           size()
894
 
#define MX_BIT_SET(x, y)                                        (x)->set(y)
895
 
//#define MX_BIT_FAST_TEST_AND_SET(x, y)                (x)->testAndSet(y)
896
 
#define MX_BIT_FAST_TEST_AND_SET(x, y)          (x)->test(y)
 
869
#define MX_BITMAP                                                       drizzled::MyBitmap
 
870
#define MX_BIT_SIZE()                                           numOfBitsInMap()
 
871
#define MX_BIT_SET(x, y)                                        (x)->setBit(y)
 
872
#define MX_BIT_FAST_TEST_AND_SET(x, y)                          (x)->testAndSet(y)
897
873
 
898
874
#define my_bool                                                         bool
899
875
//#define int16                                                         int16_t
939
915
 
940
916
#define my_pthread_setspecific_ptr(T, V)        pthread_setspecific(T, (void*) (V))
941
917
 
942
 
/* TODO: This is dangerous! */
943
 
#define mysql_real_data_home                            ::drizzled::getDataHomeCatalog().file_string().c_str()
 
918
#define mysql_real_data_home                            ::drizzled::data_home
944
919
 
945
920
#define mi_int4store(T,A)   { uint32_t def_temp= (uint32_t) (A);\
946
921
                              ((unsigned char*) (T))[3]= (unsigned char) (def_temp);\
959
934
class Session;
960
935
}
961
936
 
962
 
#define RECORD_0                                                        getInsertRecord()
963
 
#define TABLE_RECORD_0                                          getTable()->getInsertRecord()
964
 
#define TABLE_FIELDS                                            table->getFields()
965
 
#define MYSQL_LOCK(x)                                           x.lock
966
 
#define MYSQL_UNLOCK(x)                                         x.unlock
967
 
#define MYSQL_INIT_LOCK(x, y)                           x.init(y)
968
 
#define MYSQL_FREE_LOCK(x)                                      x.deinit()
969
937
 
970
938
#else // DRIZZLED
971
 
 
972
939
/* The MySQL case: */
973
940
#if MYSQL_VERSION_ID >= 50404
974
941
#define STRUCT_TABLE                                            struct TABLE
991
958
#define MX_ULONGLONG_T                                          ulonglong
992
959
#define MX_LONGLONG_T                                           longlong
993
960
#define MX_CHARSET_INFO                                         struct charset_info_st
994
 
#ifdef MARIADB_BASE_VERSION
995
 
#define MX_CONST_CHARSET_INFO                           const struct charset_info_st
996
 
#else
997
 
#define MX_CONST_CHARSET_INFO                           struct charset_info_st
998
 
#endif                  
 
961
#define MX_CONST_CHARSET_INFO                           struct charset_info_st                  
999
962
#define MX_CONST                                                        
1000
963
#define MX_BITMAP                                                       MY_BITMAP
1001
964
#define MX_BIT_SIZE()                                           n_bits
1002
965
#define MX_BIT_SET(x, y)                                        bitmap_set_bit(x, y)
1003
966
 
1004
 
#define RECORD_0                                                        record[0]
1005
 
#define TABLE_RECORD_0                                          table->record[0]
1006
 
#define TABLE_FIELDS                                            table->field
1007
 
#define MYSQL_LOCK(x)                                           pthread_mutex_lock(&x)
1008
 
#define MYSQL_UNLOCK(x)                                         pthread_mutex_unlock(&x)
1009
 
#define MYSQL_INIT_LOCK(x, y)                           thr_lock_data_init(y, &x, NULL);
1010
 
#define MYSQL_FREE_LOCK(x)                                      thr_lock_delete(&x)
1011
 
 
1012
967
#endif // DRIZZLED
1013
968
 
1014
 
#define MX_BIT_IS_SUBSET(x, y)                          x->is_subset_of(y)
 
969
#define MX_BIT_IS_SUBSET(x, y)                          bitmap_is_subset(x, y)
1015
970
 
1016
971
#ifndef XT_SCAN_CORE_DEFINED
1017
972
#define XT_SCAN_CORE_DEFINED