~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/myxt_xt.cc

Lowercase plugin name prefix.

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
 * 2006-05-16   Paul McCullagh
20
20
 *
28
28
#include "xt_defs.h"
29
29
 
30
30
#ifdef DRIZZLED
31
 
#include <drizzled/internal/my_pthread.h>
32
31
#include <drizzled/plugin.h>
33
 
#include <drizzled/plugin/client.h>
34
 
#include <drizzled/plugin/null_client.h>
35
 
#include <drizzled/plugin/listen.h>
36
32
#include <drizzled/show.h>
37
33
#include <drizzled/data_home.h>
38
34
#include <drizzled/field/blob.h>
44
40
#include <drizzled/charset_info.h>
45
41
#include <plugin/myisam/my_handler.h>
46
42
#include <plugin/myisam/myisampack.h>
47
 
#include <boost/filesystem.hpp>
48
43
//extern "C" struct charset_info_st *session_charset(Session *session);
49
44
extern pthread_key_t THR_Session;
50
45
 
51
 
namespace fs=boost::filesystem;
52
46
using namespace drizzled;
53
47
#else
54
48
#include "mysql_priv.h"
67
61
#include "database_xt.h"
68
62
#include "cache_xt.h"
69
63
#include "datalog_xt.h"
70
 
#include "memory_xt.h"
71
64
 
72
65
static void             myxt_bitmap_init(XTThreadPtr self, MX_BITMAP *map, u_int n_bits);
73
66
static void             myxt_bitmap_free(XTThreadPtr self, MX_BITMAP *map);
614
607
 */
615
608
static void mx_set_notnull_in_record(STRUCT_TABLE *table, Field *field, char *record)
616
609
{
 
610
#ifdef DRIZZLED
617
611
        if (field->null_ptr)
618
612
                record[(uint) (field->null_ptr - (uchar *) table->getDefaultValues())] &= (uchar) ~field->null_bit;
 
613
#else
 
614
        ASSERT(table == field->table);
 
615
        if (field->null_ptr)
 
616
                record[(uint) (field->null_ptr - (uchar *) table->record[0])] &= (uchar) ~field->null_bit;
 
617
#endif
619
618
}
620
619
 
621
620
static xtBool mx_is_null_in_record(STRUCT_TABLE *table, Field *field, char *record)
622
621
{
623
622
        if (field->null_ptr) {
 
623
#ifdef DRIZZLED
624
624
                if (record[(uint) (field->null_ptr - (uchar *) table->getDefaultValues())] & (uchar) field->null_bit)
625
625
                        return TRUE;
 
626
#else
 
627
                ASSERT(table == field->table);
 
628
                if (record[(uint) (field->null_ptr - (uchar *) table->record[0])] & (uchar) field->null_bit)
 
629
                        return TRUE;
 
630
#endif
626
631
        }
627
632
        return FALSE;
628
633
}
636
641
{
637
642
        char *from;
638
643
        
 
644
#ifdef DRIZZLED
639
645
        from = dest + field->offset(table->getDefaultValues());
 
646
#else
 
647
        ASSERT(table == field->table);
 
648
        from = dest + field->offset(table->record[0]);
 
649
#endif
640
650
        switch (field->real_type()) {
641
651
#ifndef DRIZZLED
642
652
                case MYSQL_TYPE_TINY_BLOB:
663
673
                        memcpy(&data, ((char *) from)+packlength, sizeof(char*));
664
674
                        
665
675
                        //*len = ((Field_blob *) field)->get_length((byte *) from);
666
 
                        *len = ((Field_blob *) field)->get_length((byte *) from, GET_TABLE_SHARE(table)->db_low_byte_first);
 
676
                        *len = ((Field_blob *) field)->get_length((byte *) from, packlength, GET_TABLE_SHARE(table)->db_low_byte_first);
667
677
                        return data;
668
678
                }
669
679
#ifndef DRIZZLED
688
698
                case MYSQL_TYPE_VARCHAR: {
689
699
                        uint length;
690
700
 
691
 
                        if (((Field_varstring *) field)->pack_length_no_ptr() == 1)
 
701
                        if (((Field_varstring *) field)->length_bytes == 1)
692
702
                                length = *((unsigned char *) from);
693
703
                        else
694
704
                                length = uint2korr(from);
695
705
                        
696
706
                        *len = length;
697
 
                        return from+((Field_varstring *) field)->pack_length_no_ptr();
 
707
                        return from+((Field_varstring *) field)->length_bytes;
698
708
                }
699
709
#ifndef DRIZZLED
700
710
                case MYSQL_TYPE_DECIMAL:
727
737
                case DRIZZLE_TYPE_DATE:
728
738
                case DRIZZLE_TYPE_DECIMAL:
729
739
                case DRIZZLE_TYPE_ENUM:
730
 
                case DRIZZLE_TYPE_UUID:
731
740
#endif
732
741
                        break;
733
742
        }
755
764
{
756
765
        char *from;
757
766
        
 
767
#ifdef DRIZZLED
758
768
        from = dest + field->offset(table->getDefaultValues());
 
769
#else
 
770
        ASSERT(table == field->table);
 
771
        from = dest + field->offset(table->record[0]);
 
772
#endif
759
773
        switch (field->real_type()) {
760
774
#ifndef DRIZZLED
761
775
                case MYSQL_TYPE_TINY_BLOB:
773
787
                        */
774
788
                        xtWord4 packlength = ((Field_blob *) field)->pack_length_no_ptr();
775
789
 
776
 
                        ((Field_blob *) field)->store_length((byte *) from, len, GET_TABLE_SHARE(table)->db_low_byte_first);
 
790
                        ((Field_blob *) field)->store_length((byte *) from, packlength, len, GET_TABLE_SHARE(table)->db_low_byte_first);
777
791
                        memcpy_fixed(((char *) from)+packlength, &data, sizeof(char*));
778
792
 
779
793
                        if (data)
783
797
#ifndef DRIZZLED
784
798
                case MYSQL_TYPE_STRING:
785
799
                        if (data) {
786
 
                                mx_set_notnull_in_record(field, dest);
 
800
                                mx_set_notnull_in_record(table, field, dest);
787
801
                                memcpy(from, data, len);
788
802
                        }
789
803
                        else
795
809
                case MYSQL_TYPE_VAR_STRING:
796
810
                        int2store(from, len);
797
811
                        if (data) {
798
 
                                mx_set_notnull_in_record(field, dest);
 
812
                                mx_set_notnull_in_record(table, field, dest);
799
813
                                memcpy(from+HA_KEY_BLOB_LENGTH, data, len);
800
814
                        }
801
815
                        return;
802
816
#endif
803
817
                case MYSQL_TYPE_VARCHAR:
804
 
                        if (((Field_varstring *) field)->pack_length_no_ptr() == 1)
 
818
                        if (((Field_varstring *) field)->length_bytes == 1)
805
819
                                *((unsigned char *) from) = (unsigned char) len;
806
820
                        else
807
821
                                int2store(from, len);
808
822
                        if (data) {
809
823
                                mx_set_notnull_in_record(table, field, dest);
810
 
                                memcpy(from+((Field_varstring *) field)->pack_length_no_ptr(), data, len);
 
824
                                memcpy(from+((Field_varstring *) field)->length_bytes, data, len);
811
825
                        }
812
826
                        return;
813
827
#ifndef DRIZZLED
841
855
                case DRIZZLE_TYPE_DATE:
842
856
                case DRIZZLE_TYPE_DECIMAL:
843
857
                case DRIZZLE_TYPE_ENUM:
844
 
                case DRIZZLE_TYPE_UUID:
845
858
#endif
846
859
                        break;
847
860
        }
904
917
         * the value of any other feilds.
905
918
         *
906
919
         * I was setting all to NULL:
907
 
        memset(dest_buff, 0xFF, GET_TABLE_SHARE(table)->null_bytes);
 
920
        memset(dest_buff, 0xFF, table->s->null_bytes);
908
921
        */
909
922
        key = (byte *) b_value;
910
923
        key_end = key + key_len;
1140
1153
#endif
1141
1154
                        case HA_KEYTYPE_LONG_INT:
1142
1155
                        case HA_KEYTYPE_ULONG_INT:
 
1156
                        case HA_KEYTYPE_UINT24:
1143
1157
                        case HA_KEYTYPE_DOUBLE:
1144
1158
                        case HA_KEYTYPE_LONGLONG:
1145
1159
                        case HA_KEYTYPE_ULONGLONG:
1151
1165
        }
1152
1166
 
1153
1167
        end:
1154
 
        u_int ilen = (xtWord1 *) key_data - key_buf;
1155
 
        if (ilen > XT_INDEX_MAX_KEY_SIZE)
1156
 
                ind->mi_key_corrupted = TRUE;
1157
 
        return ilen;
 
1168
        return (xtWord1 *) key_data - key_buf;
1158
1169
}
1159
1170
 
1160
1171
/* Derived from ha_key_cmp */
1350
1361
                                b += keyseg->length;
1351
1362
                                break;
1352
1363
                        }
 
1364
#endif
1353
1365
                        case HA_KEYTYPE_UINT24: {
1354
1366
                                int32_t l_1 = uint3korr(a);
1355
1367
                                int32_t l_2 = uint3korr(b);
1359
1371
                                b += keyseg->length;
1360
1372
                                break;
1361
1373
                        }
 
1374
#ifndef DRIZZLED
1362
1375
                        case HA_KEYTYPE_FLOAT: {
1363
1376
                                float f_1, f_2;
1364
1377
 
1526
1539
                case HA_KEYTYPE_USHORT_INT:
1527
1540
                case HA_KEYTYPE_INT24:
1528
1541
                case HA_KEYTYPE_FLOAT:
1529
 
                case HA_KEYTYPE_UINT24:
1530
1542
#endif          
1531
1543
                case HA_KEYTYPE_LONG_INT:
1532
1544
                case HA_KEYTYPE_ULONG_INT:
 
1545
                case HA_KEYTYPE_UINT24:
1533
1546
                case HA_KEYTYPE_DOUBLE:
1534
1547
                        break;
1535
1548
#ifndef DRIZZLED
1842
1855
                save = field->ptr;
1843
1856
                xt_lock_mutex(self, &tab->tab_dic_field_lock);
1844
1857
                pushr_(xt_unlock_mutex, &tab->tab_dic_field_lock);
 
1858
#ifdef DRIZZLED
1845
1859
                field->ptr = (byte *) buffer + field->offset(table->getDefaultValues());
1846
 
                field->val_str_internal(&val);
 
1860
#else
 
1861
                field->ptr = (byte *) buffer + field->offset(field->table->record[0]);
 
1862
#endif
 
1863
                field->val_str(&val);
1847
1864
                field->ptr = save;                                      // Restore org row pointer
1848
1865
                freer_(); // xt_unlock_mutex(&tab->tab_dic_field_lock)
1849
1866
                xt_strcpy(len, value, val.c_ptr());
1870
1887
        save = field->ptr;
1871
1888
        xt_lock_mutex(self, &tab->tab_dic_field_lock);
1872
1889
        pushr_(xt_unlock_mutex, &tab->tab_dic_field_lock);
 
1890
#ifdef DRIZZLED
1873
1891
        field->ptr = (byte *) buffer + field->offset(table->getDefaultValues());
 
1892
#else
 
1893
        field->ptr = (byte *) buffer + field->offset(field->table->record[0]);
 
1894
#endif
1874
1895
        error = field->store(value, len, &my_charset_utf8_general_ci);
1875
1896
        field->ptr = save;                                      // Restore org row pointer
1876
1897
        freer_(); // xt_unlock_mutex(&tab->tab_dic_field_lock)
1987
2008
 * MySQL Data Dictionary
1988
2009
 */
1989
2010
 
 
2011
#ifdef DRIZZLED
1990
2012
static void my_close_table(STRUCT_TABLE *share)
1991
2013
{
1992
2014
        delete share;
2033
2055
                        message::Table::STANDARD);
2034
2056
        }
2035
2057
        else {
2036
 
          fs::path n(getDataHomeCatalog());
2037
 
          n /= database_name;
2038
 
          n /= tab_file_name;
2039
 
                ident = new TableIdentifier(database_name, tab_name, n.file_string());
 
2058
                std::string n;
 
2059
                n.append(data_home);
 
2060
                n.append("/");
 
2061
                n.append(database_name);
 
2062
                n.append("/");
 
2063
                n.append(tab_file_name);
 
2064
                ident = new TableIdentifier(database_name, tab_name, n);
2040
2065
        }
2041
2066
        
2042
2067
        share = new TableShare(message::Table::STANDARD);
2049
2074
 
2050
2075
        return share;
2051
2076
}
 
2077
#else // DRIZZLED
 
2078
static void my_close_table(STRUCT_TABLE *table)
 
2079
{
 
2080
#ifdef DRIZZLED
 
2081
#if 0 // Removed by Brian
 
2082
        TABLE_SHARE     *share;
 
2083
 
 
2084
        share = (TABLE_SHARE *) ((char *) table + sizeof(TABLE));
 
2085
        share->free_table_share();
 
2086
#endif
 
2087
#else
 
2088
        delete_table(table, true);  // TODO: Q, why did Stewart remove this?
 
2089
#endif
 
2090
        xt_free_ns(table);
 
2091
}
 
2092
 
 
2093
/*
 
2094
 * This function returns NULL if the table cannot be opened 
 
2095
 * because this is not a MySQL thread.
 
2096
 */ 
 
2097
static STRUCT_TABLE *my_open_table(XTThreadPtr self, XTDatabaseHPtr XT_UNUSED(db), XTPathStrPtr tab_path, xtWord1 table_type)
 
2098
{
 
2099
        THD                     *thd = current_thd;
 
2100
        char            path_buffer[PATH_MAX];
 
2101
        char            *table_name;
 
2102
        char            database_name[XT_IDENTIFIER_NAME_SIZE];
 
2103
        size_t          size;
 
2104
        char            *buffer, *path, *db_name, *name;
 
2105
        TABLE_SHARE     *share;
 
2106
        int                     error;
 
2107
        TABLE           *table;
 
2108
 
 
2109
        /* If we have no MySQL thread, then we cannot open this table!
 
2110
         * What this means is the thread is probably the sweeper or the
 
2111
         * compactor.
 
2112
         */
 
2113
        if (!thd)
 
2114
                return NULL;
 
2115
 
 
2116
        /* GOTCHA: Check if the table name is a partitian,
 
2117
         * if so we need to remove the partition
 
2118
         * extension, in order for this to work!
 
2119
         *
 
2120
         * Reason: the parts of a partition table do not
 
2121
         * have .frm files!!
 
2122
         */
 
2123
        xt_strcpy(PATH_MAX, path_buffer, tab_path->ps_path);
 
2124
        table_name = xt_last_name_of_path(path_buffer);
 
2125
#ifndef DRIZZLED
 
2126
        char *ptr;
 
2127
 
 
2128
        if ((ptr = strstr(table_name, "#P#")))
 
2129
                *ptr = 0;
 
2130
#endif
 
2131
 
 
2132
        xt_2nd_last_name_of_path(XT_IDENTIFIER_NAME_SIZE, database_name, path_buffer);
 
2133
 
 
2134
        size = sizeof(TABLE) + sizeof(TABLE_SHARE) + 
 
2135
                strlen(path_buffer) + 1 +
 
2136
                strlen(database_name) + 1 + strlen(table_name) + 1;
 
2137
        if (!(buffer = (char *) xt_malloc(self, size)))
 
2138
                return NULL;
 
2139
        table = (TABLE *) buffer;
 
2140
        buffer += sizeof(TABLE);
 
2141
        share = (TABLE_SHARE *) buffer;
 
2142
        buffer += sizeof(TABLE_SHARE);
 
2143
 
 
2144
        path = buffer;
 
2145
        strcpy(path, path_buffer);
 
2146
        buffer += strlen(path_buffer) + 1;
 
2147
        db_name = buffer;
 
2148
        strcpy(db_name, database_name);
 
2149
        buffer += strlen(database_name) + 1;
 
2150
        name = buffer;
 
2151
        strcpy(name, table_name);
 
2152
 
 
2153
        /* Required to call 'open_table_from_share'! */
 
2154
        LEX *old_lex, new_lex;
 
2155
 
 
2156
        old_lex = thd->lex;
 
2157
        thd->lex = &new_lex;
 
2158
        new_lex.current_select= NULL;
 
2159
        lex_start(thd);
 
2160
 
 
2161
#ifdef DRIZZLED
 
2162
        char            tab_name[XT_IDENTIFIER_NAME_SIZE];
 
2163
 
 
2164
        uint32_t tab_name_len = TableIdentifier::filename_to_tablename(name, tab_name, XT_IDENTIFIER_NAME_SIZE);        
 
2165
        
 
2166
        TableIdentifier *ident = NULL;
 
2167
        if (table_type == XT_TABLE_TYPE_TEMPORARY) {
 
2168
                std::string tmp_path(drizzle_tmpdir);
 
2169
                tmp_path.append("/");
 
2170
                tmp_path.append(table_name);
 
2171
                ident = new TableIdentifier(db_name, tab_name, tmp_path);
 
2172
        } else if (table_type == XT_TABLE_TYPE_STANDARD) {
 
2173
                ident = new TableIdentifier(
 
2174
                        std::string(db_name), 
 
2175
                        std::string(tab_name, tab_name_len), 
 
2176
                        message::Table::STANDARD);
 
2177
        } else {
 
2178
                std::string n;
 
2179
                n.append(data_home);
 
2180
                n.append("/");
 
2181
                n.append(db_name);
 
2182
                n.append("/");
 
2183
                n.append(table_name);
 
2184
                //ident = new TableIdentifier(
 
2185
                //      std::string(db_name), 
 
2186
                //      std::string(tab_name, tab_name_len), 
 
2187
                //      message::Table::INTERNAL);
 
2188
                ident = new TableIdentifier(db_name, tab_name, n);
 
2189
        }
 
2190
        share->init(db_name, 0, name, path);
 
2191
        if ((error = share->open_table_def(*thd, *ident)) ||
 
2192
                (error = share->open_table_from_share(thd, "", 0, 0, *table)))
 
2193
        {
 
2194
          xt_free(self, table);
 
2195
          lex_end(&new_lex);
 
2196
          thd->lex = old_lex;
 
2197
          xt_throw_sulxterr(XT_CONTEXT, XT_ERR_LOADING_MYSQL_DIC, tab_path->ps_path, (u_long) error);
 
2198
          delete ident;
 
2199
          return NULL;
 
2200
        }
 
2201
        delete ident;
 
2202
#else
 
2203
#if MYSQL_VERSION_ID < 60000
 
2204
#if MYSQL_VERSION_ID < 50123
 
2205
        init_tmp_table_share(share, db_name, 0, name, path);
 
2206
#else
 
2207
        init_tmp_table_share(thd, share, db_name, 0, name, path);
 
2208
#endif
 
2209
#else
 
2210
#if MYSQL_VERSION_ID < 60004
 
2211
        init_tmp_table_share(share, db_name, 0, name, path);
 
2212
#else
 
2213
        init_tmp_table_share(thd, share, db_name, 0, name, path);
 
2214
#endif
 
2215
#endif
 
2216
 
 
2217
        /* If MySQL shutsdown while we are just starting up, they
 
2218
         * they kill the plugin sub-system before calling
 
2219
         * shutdown for the engine!
 
2220
         */
 
2221
        if (!ha_resolve_by_legacy_type(thd, DB_TYPE_PBXT)) {
 
2222
                xt_free(self, table);
 
2223
                lex_end(&new_lex);
 
2224
                thd->lex = old_lex;
 
2225
                xt_throw_xterr(XT_CONTEXT, XT_ERR_MYSQL_SHUTDOWN);
 
2226
                return NULL;
 
2227
        }
 
2228
 
 
2229
        if ((error = open_table_def(thd, share, 0))) {
 
2230
                xt_free(self, table);
 
2231
                lex_end(&new_lex);
 
2232
                thd->lex = old_lex;
 
2233
                xt_throw_sulxterr(XT_CONTEXT, XT_ERR_LOADING_MYSQL_DIC, tab_path->ps_path, (u_long) error);
 
2234
                return NULL;
 
2235
        }
 
2236
 
 
2237
#if MYSQL_VERSION_ID >= 50404
 
2238
        if ((error = open_table_from_share(thd, share, "", 0, (uint) READ_ALL, 0, table, OTM_OPEN)))
 
2239
#else
 
2240
        if ((error = open_table_from_share(thd, share, "", 0, (uint) READ_ALL, 0, table, FALSE)))
 
2241
#endif
 
2242
        {
 
2243
                xt_free(self, table);
 
2244
                lex_end(&new_lex);
 
2245
                thd->lex = old_lex;
 
2246
                xt_throw_sulxterr(XT_CONTEXT, XT_ERR_LOADING_MYSQL_DIC, tab_path->ps_path, (u_long) error);
 
2247
                return NULL;
 
2248
        }
 
2249
#endif
 
2250
 
 
2251
        lex_end(&new_lex);
 
2252
        thd->lex = old_lex;
 
2253
 
 
2254
        /* GOTCHA: I am the plug-in!!! Therefore, I should not hold 
 
2255
         * a reference to myself. By holding this reference I prevent
 
2256
         * plugin_shutdown() and reap_plugins() in sql_plugin.cc
 
2257
         * from doing their job on shutdown!
 
2258
         */
 
2259
#ifndef DRIZZLED
 
2260
        plugin_unlock(NULL, table->s->db_plugin);
 
2261
        table->s->db_plugin = NULL;
 
2262
#endif
 
2263
        return table;
 
2264
}
 
2265
#endif // DRIZZLED
2052
2266
 
2053
2267
/*
2054
2268
static bool my_match_index(XTDDIndex *ind, KEY *index)
2055
2269
{
2056
 
        KEY_PART_INFO   *key_part;
2057
 
        KEY_PART_INFO   *key_part_end;
 
2270
        KeyPartInfo     *key_part;
 
2271
        KeyPartInfo     *key_part_end;
2058
2272
        u_int                   j;
2059
2273
        XTDDColumnRef   *cref;
2060
2274
 
2112
2326
 
2113
2327
        xt_spinlock_free(self, &mi->mi_dirty_lock);
2114
2328
        XT_INDEX_FREE_LOCK(self, mi);
2115
 
#ifndef DRIZZLED
2116
2329
        myxt_bitmap_free(self, &mi->mi_col_map);
2117
 
#endif
2118
2330
        if (mi->mi_free_list)
2119
2331
                xt_free(self, mi->mi_free_list);
2120
2332
 
2144
2356
        uint                                    options = 0;
2145
2357
        u_int                                   key_length = 0;
2146
2358
        xtBool                                  partial_field;
2147
 
    MX_BITMAP               mi_col_map;
2148
2359
 
2149
2360
        enter_();
2150
2361
 
2154
2365
        xt_spinlock_init_with_autoname(self, &ind->mi_dirty_lock);
2155
2366
        ind->mi_index_no = idx;
2156
2367
        ind->mi_flags = (index->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL | HA_UNIQUE_CHECK));
2157
 
        //ind->mi_low_byte_first = TS(table_arg)->db_low_byte_first;
2158
 
        ind->mi_key_corrupted = FALSE;
 
2368
        ind->mi_low_byte_first = GET_TABLE_SHARE(table_arg)->db_low_byte_first;
2159
2369
        ind->mi_fix_key = TRUE;
2160
2370
        ind->mi_select_total = 0;
2161
2371
        ind->mi_subset_of = 0;
2162
 
#ifdef DRIZZLED
2163
 
    mi_col_map.resize(GET_TABLE_SHARE(table_arg)->fields);      
2164
 
    mi_col_map.reset();
2165
 
    ind->mi_col_map= mi_col_map.to_ulong();
2166
 
    ind->mi_col_map_size= GET_TABLE_SHARE(table_arg)->fields;
2167
 
#else
2168
2372
        myxt_bitmap_init(self, &ind->mi_col_map, GET_TABLE_SHARE(table_arg)->fields);
2169
 
#endif
2170
2373
        
2171
2374
        ind->mi_seg_count = (uint) index->key_parts;
2172
2375
        key_part_end = index->key_part + index->key_parts;
2200
2403
                        }
2201
2404
                }
2202
2405
 
2203
 
                seg->col_idx = field->position();
 
2406
                seg->col_idx = field->field_index;
2204
2407
                seg->is_recs_in_range = 1;
2205
2408
                seg->is_selectivity = 1;
2206
2409
                seg->type = (int) type;
2214
2417
                        key_length++;
2215
2418
                        seg->flag |= HA_NULL_PART;
2216
2419
                        seg->null_bit = field->null_bit;
 
2420
#ifdef DRIZZLED
2217
2421
                        seg->null_pos = (uint) (field->null_ptr - (uchar*) table_arg->getDefaultValues());
 
2422
#else
 
2423
                        seg->null_pos = (uint) (field->null_ptr - (uchar*) table_arg->record[0]);
 
2424
#endif
2218
2425
                }
2219
2426
                else {
2220
2427
                        seg->null_bit = 0;
2245
2452
                else if (field->type() == MYSQL_TYPE_BIT) {
2246
2453
                        seg->bit_length = ((Field_bit *) field)->bit_len;
2247
2454
                        seg->bit_start = ((Field_bit *) field)->bit_ofs;
2248
 
                        seg->bit_pos = (uint) (((Field_bit *) field)->bit_ptr - (uchar*) table_arg->getInsertRecord());
 
2455
                        seg->bit_pos = (uint) (((Field_bit *) field)->bit_ptr - (uchar*) table_arg->record[0]);
2249
2456
                }
2250
2457
#else
2251
2458
                /* Drizzle uses HA_KEYTYPE_ULONG_INT keys for enums > 1 byte, which is not consistent with MySQL, so we fix it here  */
2257
2464
#else
2258
2465
                                        seg->type = HA_KEYTYPE_USHORT_INT;
2259
2466
                                        break;
 
2467
#endif
2260
2468
                                case 3:
2261
2469
                                        seg->type = HA_KEYTYPE_UINT24;
2262
2470
                                        break;
2263
 
#endif
2264
2471
                        }
2265
2472
                }
2266
2473
#endif
2313
2520
 
2314
2521
                /* NOTE: do not set if the field is only partially in the index!!! */
2315
2522
                if (!partial_field)
2316
 
#ifdef DRIZZLED
2317
 
                        MX_BIT_FAST_TEST_AND_SET(&mi_col_map, field->position());
2318
 
#else
2319
 
                        MX_BIT_FAST_TEST_AND_SET(&ind->mi_col_map, field->position());
2320
 
#endif
 
2523
                        MX_BIT_FAST_TEST_AND_SET(&ind->mi_col_map, field->field_index);
2321
2524
        }
2322
2525
 
2323
2526
        if (key_length > XT_INDEX_MAX_KEY_SIZE)
2440
2643
                for (key_part = index->key_part; key_part != key_part_end; key_part++) {
2441
2644
                        curr_field = key_part->field;
2442
2645
 
2443
 
                        if ((u_int) curr_field->position()+1 > dic->dic_ind_cols_req)
2444
 
                                dic->dic_ind_cols_req = curr_field->position()+1;
 
2646
                        if ((u_int) curr_field->field_index+1 > dic->dic_ind_cols_req)
 
2647
                                dic->dic_ind_cols_req = curr_field->field_index+1;
2445
2648
                }
2446
2649
        }
2447
2650
 
2478
2681
                                else
2479
2682
                                        max_ave_row_size = 200;
2480
2683
                                large_blob_field_count++;
2481
 
                                if ((u_int) curr_field->position()+1 > dic->dic_blob_cols_req)
2482
 
                                        dic->dic_blob_cols_req = curr_field->position()+1;
 
2684
                                if ((u_int) curr_field->field_index+1 > dic->dic_blob_cols_req)
 
2685
                                        dic->dic_blob_cols_req = curr_field->field_index+1;
2483
2686
                                dic->dic_blob_count++;
2484
2687
                                xt_realloc(self, (void **) &dic->dic_blob_cols, sizeof(Field *) * dic->dic_blob_count);
2485
2688
                                dic->dic_blob_cols[dic->dic_blob_count-1] = curr_field;
2664
2867
                        field=GET_TABLE_FIELDS(my_tab);
2665
2868
                        
2666
2869
                        curr_field = field[dic->dic_ind_cols_req];
 
2870
#ifdef DRIZZLED
2667
2871
                        dic->dic_ind_rec_len = curr_field->offset(my_tab->getDefaultValues());
 
2872
#else
 
2873
                        dic->dic_ind_rec_len = curr_field->offset(my_tab->record[0]);
 
2874
#endif
2668
2875
                }
2669
2876
        }
2670
2877
 
2950
3157
 * MySQL CHARACTER UTILITIES
2951
3158
 */
2952
3159
 
2953
 
xtPublic void myxt_static_convert_identifier(XTThreadPtr XT_UNUSED(self), MX_CONST_CHARSET_INFO *cs, char *from, char *to, size_t to_len)
 
3160
xtPublic void myxt_static_convert_identifier(XTThreadPtr XT_UNUSED(self), MX_CHARSET_INFO *cs, char *from, char *to, size_t to_len)
2954
3161
{
2955
3162
#ifdef DRIZZLED
2956
 
        ((void)cs);
 
3163
        ((void *)cs);
2957
3164
         xt_strcpy(to_len, to, from);
2958
3165
#else
2959
3166
        uint errors;
2971
3178
}
2972
3179
 
2973
3180
// cs == current_thd->charset()
2974
 
xtPublic char *myxt_convert_identifier(XTThreadPtr self, MX_CONST_CHARSET_INFO *cs, char *from)
 
3181
xtPublic char *myxt_convert_identifier(XTThreadPtr self, MX_CHARSET_INFO *cs, char *from)
2975
3182
{
2976
3183
#ifdef DRIZZLED
2977
3184
        char *to = xt_dup_string(self, from);
2978
 
        ((void)cs);
 
3185
        ((void *)cs);
2979
3186
#else
2980
3187
        uint    errors;
2981
3188
        u_int   len;
3030
3237
 
3031
3238
xtPublic void myxt_static_convert_file_name(char *from, char *to, size_t to_len)
3032
3239
{
3033
 
        uint32_t len = TableIdentifier::filename_to_tablename(from, to, to_len);
3034
 
        if (len >= to_len)
3035
 
                len = to_len-1;
3036
 
        to[len] = 0;
 
3240
  TableIdentifier::filename_to_tablename(from, to, to_len);
3037
3241
}
3038
3242
 
3039
3243
xtPublic int myxt_strcasecmp(char * a, char *b)
3041
3245
        return my_strcasecmp(&my_charset_utf8_general_ci, a, b);
3042
3246
}
3043
3247
 
3044
 
xtPublic int myxt_isspace(MX_CONST_CHARSET_INFO *cs, char a)
 
3248
xtPublic int myxt_isspace(MX_CHARSET_INFO *cs, char a)
3045
3249
{
3046
3250
        return my_isspace(cs, a);
3047
3251
}
3048
3252
 
3049
 
xtPublic int myxt_ispunct(MX_CONST_CHARSET_INFO *cs, char a)
 
3253
xtPublic int myxt_ispunct(MX_CHARSET_INFO *cs, char a)
3050
3254
{
3051
3255
        return my_ispunct(cs, a);
3052
3256
}
3053
3257
 
3054
 
xtPublic int myxt_isdigit(MX_CONST_CHARSET_INFO *cs, char a)
 
3258
xtPublic int myxt_isdigit(MX_CHARSET_INFO *cs, char a)
3055
3259
{
3056
3260
        return my_isdigit(cs, a);
3057
3261
}
3058
3262
 
3059
 
xtPublic MX_CONST_CHARSET_INFO *myxt_getcharset(bool convert)
 
3263
xtPublic MX_CHARSET_INFO *myxt_getcharset(bool convert)
3060
3264
{
3061
3265
        if (convert) {
3062
3266
                THD *thd = current_thd;
3063
3267
 
3064
3268
                if (thd)
3065
 
                        return (MX_CHARSET_INFO *)thd->charset();
 
3269
                        return (MX_CHARSET_INFO *)thd_charset(thd);
3066
3270
        }
3067
3271
        return (MX_CHARSET_INFO *)&my_charset_utf8_general_ci;
3068
3272
}
3081
3285
xtPublic void *myxt_create_thread()
3082
3286
{
3083
3287
#ifdef DRIZZLED
3084
 
        Client          *client;
3085
 
        Session         *session;
3086
 
 
3087
 
        if (drizzled::internal::my_thread_init()) {
3088
 
                xt_register_error(XT_REG_CONTEXT, XT_ERR_MYSQL_ERROR, 0, "Unable to initialize MySQL threading");
3089
 
                return NULL;
3090
 
        }
3091
 
 
3092
 
        if (!(client = new NullClient()))
3093
 
                return NULL;
3094
 
        session = new Session(client);
3095
 
        session->thread_stack = (char *) &session;
3096
 
        session->storeGlobals();
3097
 
        return (void *) session;
 
3288
        return (void *) 1;
3098
3289
#else
3099
3290
        THD *new_thd;
3100
3291
 
3172
3363
}
3173
3364
 
3174
3365
#ifdef DRIZZLED
3175
 
xtPublic void myxt_destroy_thread(void *s, xtBool end_threads)
3176
 
{
3177
 
        Session *session = (Session *) s;
3178
 
 
3179
 
        delete session;
3180
 
 
3181
 
        if (end_threads)
3182
 
          drizzled::internal::my_thread_end();
 
3366
xtPublic void myxt_destroy_thread(void *, xtBool)
 
3367
{
 
3368
}
 
3369
 
 
3370
xtPublic void myxt_delete_remaining_thread()
 
3371
{
3183
3372
}
3184
3373
#else
3185
3374
xtPublic void myxt_destroy_thread(void *thread, xtBool end_threads)
3208
3397
        if (end_threads)
3209
3398
                my_thread_end();
3210
3399
}
3211
 
#endif
3212
3400
 
3213
3401
xtPublic void myxt_delete_remaining_thread()
3214
3402
{
3217
3405
        if ((thd = current_thd))
3218
3406
                myxt_destroy_thread((void *) thd, TRUE);
3219
3407
}
 
3408
#endif
3220
3409
 
3221
3410
xtPublic XTThreadPtr myxt_get_self()
3222
3411
{
3361
3550
 
3362
3551
static void myxt_bitmap_init(XTThreadPtr self, MX_BITMAP *map, u_int n_bits)
3363
3552
{
3364
 
#ifdef DRIZZLED
3365
 
    (void) self;
3366
 
    map= new boost::dynamic_bitset<>(n_bits);
3367
 
    map->resize(n_bits);
3368
 
    map->reset();
3369
 
#else
3370
3553
        my_bitmap_map   *buf;
3371
3554
    uint                        size_in_bytes = (((n_bits) + 31) / 32) * 4;
 
3555
 
3372
3556
        buf = (my_bitmap_map *) xt_malloc(self, size_in_bytes);
 
3557
 
 
3558
#ifdef DRIZZLED
 
3559
        map->init(buf, n_bits);
 
3560
#else
3373
3561
        map->bitmap= buf;
3374
3562
        map->n_bits= n_bits;
3375
3563
        create_last_word_mask(map);
3380
3568
static void myxt_bitmap_free(XTThreadPtr self, MX_BITMAP *map)
3381
3569
{
3382
3570
#ifdef DRIZZLED
3383
 
    (void) self;
3384
 
    if (map->empty())
3385
 
        map->clear();
3386
 
    delete map;
 
3571
        my_bitmap_map *buf = map->getBitmap();
 
3572
        if (buf)
 
3573
                xt_free(self, buf);
 
3574
        map->setBitmap(NULL);
3387
3575
#else
3388
3576
        if (map->bitmap) {
3389
3577
                xt_free(self, map->bitmap);