~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-05-17 23:12:39 UTC
  • Revision ID: brian@gaz-20100517231239-kgcnn613z0gga7ie
Code shuffle on ReadRecord

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
 *
25
25
 */
26
26
 
27
27
#include "xt_config.h"
28
 
#include "xt_defs.h"
29
28
 
30
29
#ifdef DRIZZLED
31
 
#include <drizzled/internal/my_pthread.h>
32
30
#include <drizzled/plugin.h>
33
 
#include <drizzled/plugin/client.h>
34
 
#include <drizzled/plugin/null_client.h>
35
 
#include <drizzled/plugin/listen.h>
36
31
#include <drizzled/show.h>
37
32
#include <drizzled/data_home.h>
38
33
#include <drizzled/field/blob.h>
44
39
#include <drizzled/charset_info.h>
45
40
#include <plugin/myisam/my_handler.h>
46
41
#include <plugin/myisam/myisampack.h>
47
 
#include <boost/filesystem.hpp>
48
42
//extern "C" struct charset_info_st *session_charset(Session *session);
49
43
extern pthread_key_t THR_Session;
50
44
 
51
 
namespace fs=boost::filesystem;
52
45
using namespace drizzled;
53
46
#else
54
47
#include "mysql_priv.h"
67
60
#include "database_xt.h"
68
61
#include "cache_xt.h"
69
62
#include "datalog_xt.h"
70
 
#include "memory_xt.h"
71
63
 
72
64
static void             myxt_bitmap_init(XTThreadPtr self, MX_BITMAP *map, u_int n_bits);
73
65
static void             myxt_bitmap_free(XTThreadPtr self, MX_BITMAP *map);
612
604
 * null_ptr refers to my buffer. If I cannot, then I
613
605
 * cannot use the set_notnull() method.
614
606
 */
615
 
static void mx_set_notnull_in_record(STRUCT_TABLE *table, Field *field, char *record)
 
607
static void mx_set_notnull_in_record(Field *field, char *record)
616
608
{
617
609
        if (field->null_ptr)
618
 
                record[(uint) (field->null_ptr - (uchar *) table->getDefaultValues())] &= (uchar) ~field->null_bit;
 
610
                record[(uint) (field->null_ptr - (uchar *) field->table->record[0])] &= (uchar) ~field->null_bit;
619
611
}
620
612
 
621
 
static xtBool mx_is_null_in_record(STRUCT_TABLE *table, Field *field, char *record)
 
613
static xtBool mx_is_null_in_record(Field *field, char *record)
622
614
{
623
615
        if (field->null_ptr) {
624
 
                if (record[(uint) (field->null_ptr - (uchar *) table->getDefaultValues())] & (uchar) field->null_bit)
 
616
                if (record[(uint) (field->null_ptr - (uchar *) field->table->record[0])] & (uchar) field->null_bit)
625
617
                        return TRUE;
626
618
        }
627
619
        return FALSE;
632
624
 * method that just returns the byte length and
633
625
 * pointer to the data in a row.
634
626
 */
635
 
static char *mx_get_length_and_data(STRUCT_TABLE *table, Field *field, char *dest, xtWord4 *len)
 
627
static char *mx_get_length_and_data(Field *field, char *dest, xtWord4 *len)
636
628
{
637
629
        char *from;
638
630
        
639
 
        from = dest + field->offset(table->getDefaultValues());
 
631
#if MYSQL_VERSION_ID < 50114
 
632
        from = dest + field->offset();
 
633
#else
 
634
        from = dest + field->offset(field->table->record[0]);
 
635
#endif
640
636
        switch (field->real_type()) {
641
637
#ifndef DRIZZLED
642
638
                case MYSQL_TYPE_TINY_BLOB:
658
654
                        field->ptr = save;                                      // Restore org row pointer
659
655
                        */
660
656
 
661
 
                        xtWord4 packlength = ((Field_blob *) field)->pack_length_no_ptr();
662
 
 
 
657
                        xtWord4 packlength = ((Field_blob *) field)->pack_length() - field->table->s->blob_ptr_size;
663
658
                        memcpy(&data, ((char *) from)+packlength, sizeof(char*));
664
659
                        
665
 
                        //*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);
 
660
                        *len = ((Field_blob *) field)->get_length((byte *) from);
667
661
                        return data;
668
662
                }
669
663
#ifndef DRIZZLED
688
682
                case MYSQL_TYPE_VARCHAR: {
689
683
                        uint length;
690
684
 
691
 
                        if (((Field_varstring *) field)->pack_length_no_ptr() == 1)
 
685
                        if (((Field_varstring *) field)->length_bytes == 1)
692
686
                                length = *((unsigned char *) from);
693
687
                        else
694
688
                                length = uint2korr(from);
695
689
                        
696
690
                        *len = length;
697
 
                        return from+((Field_varstring *) field)->pack_length_no_ptr();
 
691
                        return from+((Field_varstring *) field)->length_bytes;
698
692
                }
699
693
#ifndef DRIZZLED
700
694
                case MYSQL_TYPE_DECIMAL:
727
721
                case DRIZZLE_TYPE_DATE:
728
722
                case DRIZZLE_TYPE_DECIMAL:
729
723
                case DRIZZLE_TYPE_ENUM:
730
 
                case DRIZZLE_TYPE_UUID:
731
724
#endif
732
725
                        break;
733
726
        }
751
744
 * bug number 154 in the MySQL bug database: GROUP BY
752
745
 * and DISTINCT could treat NULL values inequal".
753
746
 */
754
 
static void mx_set_length_and_data(STRUCT_TABLE *table, Field *field, char *dest, xtWord4 len, char *data)
 
747
static void mx_set_length_and_data(Field *field, char *dest, xtWord4 len, char *data)
755
748
{
756
749
        char *from;
757
750
        
758
 
        from = dest + field->offset(table->getDefaultValues());
 
751
#if MYSQL_VERSION_ID < 50114
 
752
        from = dest + field->offset();
 
753
#else
 
754
        from = dest + field->offset(field->table->record[0]);
 
755
#endif
759
756
        switch (field->real_type()) {
760
757
#ifndef DRIZZLED
761
758
                case MYSQL_TYPE_TINY_BLOB:
771
768
                        ((Field_blob *) field)->set_ptr(len, data);
772
769
                        field->ptr = save;                                      // Restore org row pointer
773
770
                        */
774
 
                        xtWord4 packlength = ((Field_blob *) field)->pack_length_no_ptr();
 
771
                        xtWord4 packlength = ((Field_blob *) field)->pack_length() - field->table->s->blob_ptr_size;
775
772
 
776
 
                        ((Field_blob *) field)->store_length((byte *) from, len, GET_TABLE_SHARE(table)->db_low_byte_first);
 
773
                        ((Field_blob *) field)->store_length((byte *) from, packlength, len);
777
774
                        memcpy_fixed(((char *) from)+packlength, &data, sizeof(char*));
778
775
 
779
776
                        if (data)
780
 
                                mx_set_notnull_in_record(table, field, dest);
 
777
                                mx_set_notnull_in_record(field, dest);
781
778
                        return;
782
779
                }
783
780
#ifndef DRIZZLED
801
798
                        return;
802
799
#endif
803
800
                case MYSQL_TYPE_VARCHAR:
804
 
                        if (((Field_varstring *) field)->pack_length_no_ptr() == 1)
 
801
                        if (((Field_varstring *) field)->length_bytes == 1)
805
802
                                *((unsigned char *) from) = (unsigned char) len;
806
803
                        else
807
804
                                int2store(from, len);
808
805
                        if (data) {
809
 
                                mx_set_notnull_in_record(table, field, dest);
810
 
                                memcpy(from+((Field_varstring *) field)->pack_length_no_ptr(), data, len);
 
806
                                mx_set_notnull_in_record(field, dest);
 
807
                                memcpy(from+((Field_varstring *) field)->length_bytes, data, len);
811
808
                        }
812
809
                        return;
813
810
#ifndef DRIZZLED
841
838
                case DRIZZLE_TYPE_DATE:
842
839
                case DRIZZLE_TYPE_DECIMAL:
843
840
                case DRIZZLE_TYPE_ENUM:
844
 
                case DRIZZLE_TYPE_UUID:
845
841
#endif
846
842
                        break;
847
843
        }
848
844
 
849
845
        if (data) {
850
 
                mx_set_notnull_in_record(table, field, dest);
 
846
                mx_set_notnull_in_record(field, dest);
851
847
                memcpy(from, data, len);
852
848
        }
853
849
        else
867
863
xtPublic void myxt_set_default_row_from_key(XTOpenTablePtr ot, XTIndexPtr ind, xtWord1 *record)
868
864
{
869
865
        XTTableHPtr             tab = ot->ot_table;
870
 
        STRUCT_TABLE    *table = tab->tab_dic.dic_my_table;
 
866
        TABLE                   *table = tab->tab_dic.dic_my_table;
871
867
        XTIndexSegRec   *keyseg = ind->mi_seg;
872
868
 
873
869
        xt_lock_mutex_ns(&tab->tab_dic_field_lock);
875
871
        for (u_int i=0; i<ind->mi_seg_count; i++, keyseg++) {
876
872
                
877
873
                u_int col_idx = keyseg->col_idx;
878
 
                Field *field = GET_TABLE_FIELDS(table)[col_idx];
 
874
                Field *field = table->field[col_idx];
879
875
                byte  *field_save = field->ptr;
880
876
 
881
 
                field->ptr = GET_TABLE_SHARE(table)->getDefaultValues() + keyseg->start;
 
877
                field->ptr = table->s->default_values + keyseg->start;
882
878
                memcpy(record + keyseg->start, field->ptr, field->pack_length());
883
879
                record[keyseg->null_pos] &= ~keyseg->null_bit;
884
 
                record[keyseg->null_pos] |= GET_TABLE_SHARE(table)->getDefaultValues()[keyseg->null_pos] & keyseg->null_bit;
 
880
                record[keyseg->null_pos] |= table->s->default_values[keyseg->null_pos] & keyseg->null_bit;
885
881
 
886
882
                field->ptr = field_save;
887
883
        }
904
900
         * the value of any other feilds.
905
901
         *
906
902
         * I was setting all to NULL:
907
 
        memset(dest_buff, 0xFF, GET_TABLE_SHARE(table)->null_bytes);
 
903
        memset(dest_buff, 0xFF, table->s->null_bytes);
908
904
        */
909
905
        key = (byte *) b_value;
910
906
        key_end = key + key_len;
1140
1136
#endif
1141
1137
                        case HA_KEYTYPE_LONG_INT:
1142
1138
                        case HA_KEYTYPE_ULONG_INT:
 
1139
                        case HA_KEYTYPE_UINT24:
1143
1140
                        case HA_KEYTYPE_DOUBLE:
1144
1141
                        case HA_KEYTYPE_LONGLONG:
1145
1142
                        case HA_KEYTYPE_ULONGLONG:
1151
1148
        }
1152
1149
 
1153
1150
        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;
 
1151
        return (xtWord1 *) key_data - key_buf;
1158
1152
}
1159
1153
 
1160
1154
/* Derived from ha_key_cmp */
1350
1344
                                b += keyseg->length;
1351
1345
                                break;
1352
1346
                        }
 
1347
#endif
1353
1348
                        case HA_KEYTYPE_UINT24: {
1354
1349
                                int32_t l_1 = uint3korr(a);
1355
1350
                                int32_t l_2 = uint3korr(b);
1359
1354
                                b += keyseg->length;
1360
1355
                                break;
1361
1356
                        }
 
1357
#ifndef DRIZZLED
1362
1358
                        case HA_KEYTYPE_FLOAT: {
1363
1359
                                float f_1, f_2;
1364
1360
 
1526
1522
                case HA_KEYTYPE_USHORT_INT:
1527
1523
                case HA_KEYTYPE_INT24:
1528
1524
                case HA_KEYTYPE_FLOAT:
1529
 
                case HA_KEYTYPE_UINT24:
1530
1525
#endif          
1531
1526
                case HA_KEYTYPE_LONG_INT:
1532
1527
                case HA_KEYTYPE_ULONG_INT:
 
1528
                case HA_KEYTYPE_UINT24:
1533
1529
                case HA_KEYTYPE_DOUBLE:
1534
1530
                        break;
1535
1531
#ifndef DRIZZLED
1566
1562
 
1567
1563
xtPublic xtWord4 myxt_store_row_length(XTOpenTablePtr ot, char *rec_buff)
1568
1564
{
1569
 
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
1570
 
        char                    *sdata;
1571
 
        xtWord4                 dlen;
1572
 
        xtWord4                 item_size;
1573
 
        xtWord4                 row_size = 0;
 
1565
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
 
1566
        char    *sdata;
 
1567
        xtWord4 dlen;
 
1568
        xtWord4 item_size;
 
1569
        xtWord4 row_size = 0;
1574
1570
 
1575
 
        for (Field* const *field=GET_TABLE_FIELDS(table); *field ; field++) {
 
1571
        for (Field **field=table->field ; *field ; field++) {
1576
1572
                if ((*field)->is_null_in_record((const uchar *) rec_buff)) {
1577
1573
                        sdata = NULL;
1578
1574
                        dlen = 0;
1579
1575
                        item_size = 1;
1580
1576
                }
1581
1577
                else {
1582
 
                        sdata = mx_get_length_and_data(table, *field, rec_buff, &dlen);
 
1578
                        sdata = mx_get_length_and_data(*field, rec_buff, &dlen);
1583
1579
                        if (!dlen) {
1584
1580
                                /* Empty, but not null (blobs may return NULL, when
1585
1581
                                 * length is 0.
1604
1600
 
1605
1601
xtPublic xtWord4 myxt_store_row_data(XTOpenTablePtr ot, xtWord4 row_size, char *rec_buff)
1606
1602
{
1607
 
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
1608
 
        char                    *sdata;
1609
 
        xtWord4                 dlen;
1610
 
        xtWord4                 item_size;
 
1603
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
 
1604
        char    *sdata;
 
1605
        xtWord4 dlen;
 
1606
        xtWord4 item_size;
1611
1607
 
1612
 
        for (Field * const* field=GET_TABLE_FIELDS(table); *field; field++) {
1613
 
                if (mx_is_null_in_record(table, *field, rec_buff)) {
 
1608
        for (Field **field=table->field ; *field ; field++) {
 
1609
                if ((*field)->is_null_in_record((const uchar *) rec_buff)) {
1614
1610
                        sdata = NULL;
1615
1611
                        dlen = 0;
1616
1612
                        item_size = 1;
1617
1613
                }
1618
1614
                else {
1619
 
                        sdata = mx_get_length_and_data(table, *field, rec_buff, &dlen);
 
1615
                        sdata = mx_get_length_and_data(*field, rec_buff, &dlen);
1620
1616
                        if (!dlen) {
1621
1617
                                /* Empty, but not null (blobs may return NULL, when
1622
1618
                                 * length is 0.
1732
1728
/* Unload from PBXT variable length format to the MySQL row format. */
1733
1729
xtPublic xtWord4 myxt_load_row_data(XTOpenTablePtr ot, xtWord1 *source_buf, xtWord1 *dest_buff, u_int col_cnt)
1734
1730
{
1735
 
        xtWord1                 *input_buf = source_buf;
1736
 
        STRUCT_TABLE    *table;
1737
 
        xtWord4                 len;
1738
 
        Field                   *curr_field;
1739
 
        xtBool                  is_null;
1740
 
        u_int                   i = 0;
 
1731
        xtWord1 *input_buf = source_buf;
 
1732
        TABLE   *table;
 
1733
        xtWord4 len;
 
1734
        Field   *curr_field;
 
1735
        xtBool  is_null;
 
1736
        u_int   i = 0;
1741
1737
 
1742
1738
        if (!(table = ot->ot_table->tab_dic.dic_my_table)) {
1743
1739
                xt_register_taberr(XT_REG_CONTEXT, XT_ERR_NO_DICTIONARY, ot->ot_table->tab_name);
1749
1745
         * have the SQL NULL bit set unless it
1750
1746
         * is a nullable column with a non-NULL value".
1751
1747
         */
1752
 
        memset(dest_buff, 0xFF, GET_TABLE_SHARE(table)->null_bytes);
1753
 
        for (Field * const *field=GET_TABLE_FIELDS(table); *field && (!col_cnt || i<col_cnt); field++, i++) {
 
1748
        memset(dest_buff, 0xFF, table->s->null_bytes);
 
1749
        for (Field **field=table->field ; *field && (!col_cnt || i<col_cnt); field++, i++) {
1754
1750
                curr_field = *field;
1755
1751
                is_null = FALSE;
1756
1752
                switch (*source_buf) {
1782
1778
                }
1783
1779
 
1784
1780
                if (is_null)
1785
 
                        mx_set_length_and_data(table, curr_field, (char *) dest_buff, 0, NULL);
 
1781
                        mx_set_length_and_data(curr_field, (char *) dest_buff, 0, NULL);
1786
1782
                else
1787
 
                        mx_set_length_and_data(table, curr_field, (char *) dest_buff, len, (char *) source_buf);
 
1783
                        mx_set_length_and_data(curr_field, (char *) dest_buff, len, (char *) source_buf);
1788
1784
 
1789
1785
                source_buf += len;
1790
1786
        }
1798
1794
 
1799
1795
xtPublic xtBool myxt_find_column(XTOpenTablePtr ot, u_int *col_idx, const char *col_name)
1800
1796
{
1801
 
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
1802
 
        u_int                   i=0;
 
1797
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
 
1798
        u_int   i=0;
1803
1799
 
1804
 
        for (Field * const *field=GET_TABLE_FIELDS(table); *field; field++, i++) {
 
1800
        for (Field **field=table->field; *field; field++, i++) {
1805
1801
                if (!my_strcasecmp(system_charset_info, (*field)->field_name, col_name)) {
1806
1802
                        *col_idx = i;
1807
1803
                        return OK;
1812
1808
 
1813
1809
xtPublic void myxt_get_column_name(XTOpenTablePtr ot, u_int col_idx, u_int len, char *col_name)
1814
1810
{
1815
 
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
1816
 
        Field                   *field;
 
1811
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
 
1812
        Field   *field;
1817
1813
 
1818
 
        field = GET_TABLE_FIELDS(table)[col_idx];
 
1814
        field = table->field[col_idx];
1819
1815
        xt_strcpy(len, col_name, field->field_name);
1820
1816
}
1821
1817
 
1822
1818
xtPublic void myxt_get_column_as_string(XTOpenTablePtr ot, char *buffer, u_int col_idx, u_int len, char *value)
1823
1819
{
1824
 
        XTTableHPtr             tab = ot->ot_table;
1825
 
        XTThreadPtr             self = ot->ot_thread;
1826
 
        STRUCT_TABLE    *table = tab->tab_dic.dic_my_table;
1827
 
        Field                   *field = GET_TABLE_FIELDS(table)[col_idx];
1828
 
        char                    buf_val[MAX_FIELD_WIDTH];
1829
 
        String                  val(buf_val, sizeof(buf_val), &my_charset_bin);
 
1820
        XTTableHPtr     tab = ot->ot_table;
 
1821
        XTThreadPtr self = ot->ot_thread;
 
1822
        TABLE           *table = tab->tab_dic.dic_my_table;
 
1823
        Field           *field = table->field[col_idx];
 
1824
        char            buf_val[MAX_FIELD_WIDTH];
 
1825
        String          val(buf_val, sizeof(buf_val), &my_charset_bin);
1830
1826
 
1831
 
        if (mx_is_null_in_record(table, field, buffer))
 
1827
        if (mx_is_null_in_record(field, buffer))
1832
1828
                xt_strcpy(len, value, "NULL");
1833
1829
        else {
1834
1830
                byte    *save;
1835
1831
 
1836
 
#ifndef DRIZZLED
1837
1832
                /* Required by store() - or an assertion will fail: */
1838
1833
                if (table->read_set)
1839
1834
                        MX_BIT_SET(table->read_set, col_idx);
1840
 
#endif
1841
1835
 
1842
1836
                save = field->ptr;
1843
1837
                xt_lock_mutex(self, &tab->tab_dic_field_lock);
1844
1838
                pushr_(xt_unlock_mutex, &tab->tab_dic_field_lock);
1845
 
                field->ptr = (byte *) buffer + field->offset(table->getDefaultValues());
1846
 
                field->val_str_internal(&val);
 
1839
#if MYSQL_VERSION_ID < 50114
 
1840
                field->ptr = (byte *) buffer + field->offset();
 
1841
#else
 
1842
                field->ptr = (byte *) buffer + field->offset(field->table->record[0]);
 
1843
#endif
 
1844
                field->val_str(&val);
1847
1845
                field->ptr = save;                                      // Restore org row pointer
1848
1846
                freer_(); // xt_unlock_mutex(&tab->tab_dic_field_lock)
1849
1847
                xt_strcpy(len, value, val.c_ptr());
1852
1850
 
1853
1851
xtPublic xtBool myxt_set_column(XTOpenTablePtr ot, char *buffer, u_int col_idx, const char *value, u_int len)
1854
1852
{
1855
 
        XTTableHPtr             tab = ot->ot_table;
1856
 
        XTThreadPtr             self = ot->ot_thread;
1857
 
        STRUCT_TABLE    *table = tab->tab_dic.dic_my_table;
1858
 
        Field                   *field = GET_TABLE_FIELDS(table)[col_idx];
1859
 
        byte                    *save;
1860
 
        int                             error;
 
1853
        XTTableHPtr     tab = ot->ot_table;
 
1854
        XTThreadPtr self = ot->ot_thread;
 
1855
        TABLE           *table = tab->tab_dic.dic_my_table;
 
1856
        Field           *field = table->field[col_idx];
 
1857
        byte            *save;
 
1858
        int                     error;
1861
1859
 
1862
 
#ifndef DRIZZLED
1863
1860
        /* Required by store() - or an assertion will fail: */
1864
1861
        if (table->write_set)
1865
1862
                MX_BIT_SET(table->write_set, col_idx);
1866
 
#endif
1867
1863
 
1868
 
        mx_set_notnull_in_record(table, field, buffer);
 
1864
        mx_set_notnull_in_record(field, buffer);
1869
1865
 
1870
1866
        save = field->ptr;
1871
1867
        xt_lock_mutex(self, &tab->tab_dic_field_lock);
1872
1868
        pushr_(xt_unlock_mutex, &tab->tab_dic_field_lock);
1873
 
        field->ptr = (byte *) buffer + field->offset(table->getDefaultValues());
 
1869
#if MYSQL_VERSION_ID < 50114
 
1870
        field->ptr = (byte *) buffer + field->offset();
 
1871
#else
 
1872
        field->ptr = (byte *) buffer + field->offset(field->table->record[0]);
 
1873
#endif
1874
1874
        error = field->store(value, len, &my_charset_utf8_general_ci);
1875
1875
        field->ptr = save;                                      // Restore org row pointer
1876
1876
        freer_(); // xt_unlock_mutex(&tab->tab_dic_field_lock)
1879
1879
 
1880
1880
xtPublic void myxt_get_column_data(XTOpenTablePtr ot, char *buffer, u_int col_idx, char **value, size_t *len)
1881
1881
{
1882
 
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
1883
 
        Field                   *field = GET_TABLE_FIELDS(table)[col_idx];
1884
 
        char                    *sdata;
1885
 
        xtWord4                 dlen;
 
1882
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
 
1883
        Field   *field = table->field[col_idx];
 
1884
        char    *sdata;
 
1885
        xtWord4 dlen;
1886
1886
 
1887
 
        sdata = mx_get_length_and_data(table, field, buffer, &dlen);
 
1887
        sdata = mx_get_length_and_data(field, buffer, &dlen);
1888
1888
        *value = sdata;
1889
1889
        *len = dlen;
1890
1890
}
1987
1987
 * MySQL Data Dictionary
1988
1988
 */
1989
1989
 
1990
 
static void my_close_table(STRUCT_TABLE *share)
 
1990
#define TS(x)                                   (x)->s
 
1991
 
 
1992
static void my_close_table(TABLE *table)
1991
1993
{
1992
 
        delete share;
 
1994
#ifdef DRIZZLED
 
1995
#if 0 // Removed by Brian
 
1996
        TABLE_SHARE     *share;
 
1997
 
 
1998
        share = (TABLE_SHARE *) ((char *) table + sizeof(TABLE));
 
1999
        share->free_table_share();
 
2000
#endif
 
2001
#else
 
2002
        delete_table(table, true);  // TODO: Q, why did Stewart remove this?
 
2003
#endif
 
2004
        xt_free_ns(table);
1993
2005
}
1994
2006
 
1995
2007
/*
1996
2008
 * This function returns NULL if the table cannot be opened 
1997
2009
 * because this is not a MySQL thread.
1998
2010
 */ 
1999
 
static STRUCT_TABLE *my_open_table(XTThreadPtr self, XTDatabaseHPtr XT_UNUSED(db), XTPathStrPtr tab_path, xtWord1 table_type)
 
2011
static TABLE *my_open_table(XTThreadPtr self, XTDatabaseHPtr XT_UNUSED(db), XTPathStrPtr tab_path, xtWord1 table_type)
2000
2012
{
2001
2013
        THD                     *thd = current_thd;
2002
 
        char            *tab_file_name;
 
2014
        char            path_buffer[PATH_MAX];
 
2015
        char            *table_name;
2003
2016
        char            database_name[XT_IDENTIFIER_NAME_SIZE];
2004
 
        char            tab_name[XT_IDENTIFIER_NAME_SIZE];
2005
 
        uint32_t        tab_name_len;   
2006
 
        TableShare      *share;
 
2017
        size_t          size;
 
2018
        char            *buffer, *path, *db_name, *name;
 
2019
        TABLE_SHARE     *share;
2007
2020
        int                     error;
 
2021
        TABLE           *table;
2008
2022
 
2009
2023
        /* If we have no MySQL thread, then we cannot open this table!
2010
2024
         * What this means is the thread is probably the sweeper or the
2013
2027
        if (!thd)
2014
2028
                return NULL;
2015
2029
 
2016
 
        tab_file_name = xt_last_name_of_path(tab_path->ps_path);
2017
 
        tab_name_len = TableIdentifier::filename_to_tablename(tab_file_name, tab_name, XT_IDENTIFIER_NAME_SIZE);
2018
 
 
2019
 
        xt_2nd_last_name_of_path(XT_IDENTIFIER_NAME_SIZE, database_name, tab_path->ps_path);
2020
 
 
 
2030
        /* GOTCHA: Check if the table name is a partitian,
 
2031
         * if so we need to remove the partition
 
2032
         * extension, in order for this to work!
 
2033
         *
 
2034
         * Reason: the parts of a partition table do not
 
2035
         * have .frm files!!
 
2036
         */
 
2037
        xt_strcpy(PATH_MAX, path_buffer, tab_path->ps_path);
 
2038
        table_name = xt_last_name_of_path(path_buffer);
 
2039
#ifndef DRIZZLED
 
2040
        char *ptr;
 
2041
 
 
2042
        if ((ptr = strstr(table_name, "#P#")))
 
2043
                *ptr = 0;
 
2044
#endif
 
2045
 
 
2046
        xt_2nd_last_name_of_path(XT_IDENTIFIER_NAME_SIZE, database_name, path_buffer);
 
2047
 
 
2048
        size = sizeof(TABLE) + sizeof(TABLE_SHARE) + 
 
2049
                strlen(path_buffer) + 1 +
 
2050
                strlen(database_name) + 1 + strlen(table_name) + 1;
 
2051
        if (!(buffer = (char *) xt_malloc(self, size)))
 
2052
                return NULL;
 
2053
        table = (TABLE *) buffer;
 
2054
        buffer += sizeof(TABLE);
 
2055
        share = (TABLE_SHARE *) buffer;
 
2056
        buffer += sizeof(TABLE_SHARE);
 
2057
 
 
2058
        path = buffer;
 
2059
        strcpy(path, path_buffer);
 
2060
        buffer += strlen(path_buffer) + 1;
 
2061
        db_name = buffer;
 
2062
        strcpy(db_name, database_name);
 
2063
        buffer += strlen(database_name) + 1;
 
2064
        name = buffer;
 
2065
        strcpy(name, table_name);
 
2066
 
 
2067
        /* Required to call 'open_table_from_share'! */
 
2068
        LEX *old_lex, new_lex;
 
2069
 
 
2070
        old_lex = thd->lex;
 
2071
        thd->lex = &new_lex;
 
2072
        new_lex.current_select= NULL;
 
2073
        lex_start(thd);
 
2074
 
 
2075
#ifdef DRIZZLED
 
2076
        char            tab_name[XT_IDENTIFIER_NAME_SIZE];
 
2077
 
 
2078
        uint32_t tab_name_len = filename_to_tablename(name, tab_name, XT_IDENTIFIER_NAME_SIZE); 
 
2079
        
2021
2080
        TableIdentifier *ident = NULL;
2022
 
        
2023
2081
        if (table_type == XT_TABLE_TYPE_TEMPORARY) {
2024
2082
                std::string tmp_path(drizzle_tmpdir);
2025
2083
                tmp_path.append("/");
2026
 
                tmp_path.append(tab_file_name);
2027
 
                ident = new TableIdentifier(database_name, tab_name, tmp_path);
2028
 
        }
2029
 
        else if (table_type == XT_TABLE_TYPE_STANDARD) {
2030
 
                ident = new TableIdentifier(
2031
 
                        std::string(database_name), 
 
2084
                tmp_path.append(table_name);
 
2085
                ident = new TableIdentifier(db_name, tab_name, tmp_path);
 
2086
        } else if (table_type == XT_TABLE_TYPE_STANDARD) {
 
2087
                ident = new TableIdentifier(
 
2088
                        std::string(db_name), 
2032
2089
                        std::string(tab_name, tab_name_len), 
2033
2090
                        message::Table::STANDARD);
2034
 
        }
2035
 
        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());
2040
 
        }
2041
 
        
2042
 
        share = new TableShare(message::Table::STANDARD);
2043
 
        if ((error = share->open_table_def(*thd, *ident))) {
 
2091
        } else {
 
2092
                std::string n;
 
2093
                n.append(data_home);
 
2094
                n.append("/");
 
2095
                n.append(db_name);
 
2096
                n.append("/");
 
2097
                n.append(table_name);
 
2098
                //ident = new TableIdentifier(
 
2099
                //      std::string(db_name), 
 
2100
                //      std::string(tab_name, tab_name_len), 
 
2101
                //      message::Table::INTERNAL);
 
2102
                ident = new TableIdentifier(db_name, tab_name, n);
 
2103
        }
 
2104
        share->init(db_name, 0, name, path);
 
2105
        if ((error = share->open_table_def(*thd, *ident)) ||
 
2106
                (error = share->open_table_from_share(thd, "", 0, 0, *table)))
 
2107
        {
 
2108
          xt_free(self, table);
 
2109
          lex_end(&new_lex);
 
2110
          thd->lex = old_lex;
2044
2111
          xt_throw_sulxterr(XT_CONTEXT, XT_ERR_LOADING_MYSQL_DIC, tab_path->ps_path, (u_long) error);
2045
2112
          delete ident;
2046
2113
          return NULL;
2047
 
        }
 
2114
        }
2048
2115
        delete ident;
2049
 
 
2050
 
        return share;
 
2116
#else
 
2117
#if MYSQL_VERSION_ID < 60000
 
2118
#if MYSQL_VERSION_ID < 50123
 
2119
        init_tmp_table_share(share, db_name, 0, name, path);
 
2120
#else
 
2121
        init_tmp_table_share(thd, share, db_name, 0, name, path);
 
2122
#endif
 
2123
#else
 
2124
#if MYSQL_VERSION_ID < 60004
 
2125
        init_tmp_table_share(share, db_name, 0, name, path);
 
2126
#else
 
2127
        init_tmp_table_share(thd, share, db_name, 0, name, path);
 
2128
#endif
 
2129
#endif
 
2130
 
 
2131
        /* If MySQL shutsdown while we are just starting up, they
 
2132
         * they kill the plugin sub-system before calling
 
2133
         * shutdown for the engine!
 
2134
         */
 
2135
        if (!ha_resolve_by_legacy_type(thd, DB_TYPE_PBXT)) {
 
2136
                xt_free(self, table);
 
2137
                lex_end(&new_lex);
 
2138
                thd->lex = old_lex;
 
2139
                xt_throw_xterr(XT_CONTEXT, XT_ERR_MYSQL_SHUTDOWN);
 
2140
                return NULL;
 
2141
        }
 
2142
 
 
2143
        if ((error = open_table_def(thd, share, 0))) {
 
2144
                xt_free(self, table);
 
2145
                lex_end(&new_lex);
 
2146
                thd->lex = old_lex;
 
2147
                xt_throw_sulxterr(XT_CONTEXT, XT_ERR_LOADING_MYSQL_DIC, tab_path->ps_path, (u_long) error);
 
2148
                return NULL;
 
2149
        }
 
2150
 
 
2151
#if MYSQL_VERSION_ID >= 50404
 
2152
        if ((error = open_table_from_share(thd, share, "", 0, (uint) READ_ALL, 0, table, OTM_OPEN)))
 
2153
#else
 
2154
        if ((error = open_table_from_share(thd, share, "", 0, (uint) READ_ALL, 0, table, FALSE)))
 
2155
#endif
 
2156
        {
 
2157
                xt_free(self, table);
 
2158
                lex_end(&new_lex);
 
2159
                thd->lex = old_lex;
 
2160
                xt_throw_sulxterr(XT_CONTEXT, XT_ERR_LOADING_MYSQL_DIC, tab_path->ps_path, (u_long) error);
 
2161
                return NULL;
 
2162
        }
 
2163
#endif
 
2164
 
 
2165
        lex_end(&new_lex);
 
2166
        thd->lex = old_lex;
 
2167
 
 
2168
        /* GOTCHA: I am the plug-in!!! Therefore, I should not hold 
 
2169
         * a reference to myself. By holding this reference I prevent
 
2170
         * plugin_shutdown() and reap_plugins() in sql_plugin.cc
 
2171
         * from doing their job on shutdown!
 
2172
         */
 
2173
#ifndef DRIZZLED
 
2174
        plugin_unlock(NULL, table->s->db_plugin);
 
2175
        table->s->db_plugin = NULL;
 
2176
#endif
 
2177
        return table;
2051
2178
}
2052
2179
 
2053
2180
/*
2054
2181
static bool my_match_index(XTDDIndex *ind, KEY *index)
2055
2182
{
2056
 
        KEY_PART_INFO   *key_part;
2057
 
        KEY_PART_INFO   *key_part_end;
 
2183
        KeyPartInfo     *key_part;
 
2184
        KeyPartInfo     *key_part_end;
2058
2185
        u_int                   j;
2059
2186
        XTDDColumnRef   *cref;
2060
2187
 
2112
2239
 
2113
2240
        xt_spinlock_free(self, &mi->mi_dirty_lock);
2114
2241
        XT_INDEX_FREE_LOCK(self, mi);
2115
 
#ifndef DRIZZLED
2116
2242
        myxt_bitmap_free(self, &mi->mi_col_map);
2117
 
#endif
2118
2243
        if (mi->mi_free_list)
2119
2244
                xt_free(self, mi->mi_free_list);
2120
2245
 
2133
2258
#define MX_OFFSETOF(x, y)               ((size_t)(&((x *) 8)->y) - 8)
2134
2259
 
2135
2260
/* Derived from ha_myisam::create and mi_create */
2136
 
static XTIndexPtr my_create_index(XTThreadPtr self, STRUCT_TABLE *table_arg, u_int idx, KeyInfo *index)
 
2261
static XTIndexPtr my_create_index(XTThreadPtr self, TABLE *table_arg, u_int idx, KeyInfo *index)
2137
2262
{
2138
2263
        XTIndexPtr                              ind;
2139
2264
        KeyPartInfo                     *key_part;
2144
2269
        uint                                    options = 0;
2145
2270
        u_int                                   key_length = 0;
2146
2271
        xtBool                                  partial_field;
2147
 
    MX_BITMAP               mi_col_map;
2148
2272
 
2149
2273
        enter_();
2150
2274
 
2154
2278
        xt_spinlock_init_with_autoname(self, &ind->mi_dirty_lock);
2155
2279
        ind->mi_index_no = idx;
2156
2280
        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;
 
2281
        ind->mi_low_byte_first = TS(table_arg)->db_low_byte_first;
2159
2282
        ind->mi_fix_key = TRUE;
2160
2283
        ind->mi_select_total = 0;
2161
2284
        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
 
        myxt_bitmap_init(self, &ind->mi_col_map, GET_TABLE_SHARE(table_arg)->fields);
2169
 
#endif
 
2285
        myxt_bitmap_init(self, &ind->mi_col_map, TS(table_arg)->fields);
2170
2286
        
2171
2287
        ind->mi_seg_count = (uint) index->key_parts;
2172
2288
        key_part_end = index->key_part + index->key_parts;
2200
2316
                        }
2201
2317
                }
2202
2318
 
2203
 
                seg->col_idx = field->position();
 
2319
                seg->col_idx = field->field_index;
2204
2320
                seg->is_recs_in_range = 1;
2205
2321
                seg->is_selectivity = 1;
2206
2322
                seg->type = (int) type;
2214
2330
                        key_length++;
2215
2331
                        seg->flag |= HA_NULL_PART;
2216
2332
                        seg->null_bit = field->null_bit;
2217
 
                        seg->null_pos = (uint) (field->null_ptr - (uchar*) table_arg->getDefaultValues());
 
2333
                        seg->null_pos = (uint) (field->null_ptr - (uchar*) table_arg->record[0]);
2218
2334
                }
2219
2335
                else {
2220
2336
                        seg->null_bit = 0;
2239
2355
                        ) {
2240
2356
                        seg->flag |= HA_BLOB_PART;
2241
2357
                        /* save number of bytes used to pack length */
2242
 
                        seg->bit_start = (uint) ((Field_blob *) field)->pack_length_no_ptr();
 
2358
                        seg->bit_start = (uint) (field->pack_length() - TS(table_arg)->blob_ptr_size);
2243
2359
                }
2244
2360
#ifndef DRIZZLED
2245
2361
                else if (field->type() == MYSQL_TYPE_BIT) {
2246
2362
                        seg->bit_length = ((Field_bit *) field)->bit_len;
2247
2363
                        seg->bit_start = ((Field_bit *) field)->bit_ofs;
2248
 
                        seg->bit_pos = (uint) (((Field_bit *) field)->bit_ptr - (uchar*) table_arg->getInsertRecord());
 
2364
                        seg->bit_pos = (uint) (((Field_bit *) field)->bit_ptr - (uchar*) table_arg->record[0]);
2249
2365
                }
2250
2366
#else
2251
2367
                /* Drizzle uses HA_KEYTYPE_ULONG_INT keys for enums > 1 byte, which is not consistent with MySQL, so we fix it here  */
2257
2373
#else
2258
2374
                                        seg->type = HA_KEYTYPE_USHORT_INT;
2259
2375
                                        break;
 
2376
#endif
2260
2377
                                case 3:
2261
2378
                                        seg->type = HA_KEYTYPE_UINT24;
2262
2379
                                        break;
2263
 
#endif
2264
2380
                        }
2265
2381
                }
2266
2382
#endif
2304
2420
#endif
2305
2421
                        )
2306
2422
                {
2307
 
                        Field   *tab_field = GET_TABLE_FIELDS(table_arg)[key_part->fieldnr-1];
 
2423
                        Field   *tab_field = table_arg->field[key_part->fieldnr-1];
2308
2424
                        u_int   field_len = tab_field->key_length();
2309
2425
 
2310
2426
                        if (key_part->length != field_len)
2313
2429
 
2314
2430
                /* NOTE: do not set if the field is only partially in the index!!! */
2315
2431
                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
 
2432
                        MX_BIT_FAST_TEST_AND_SET(&ind->mi_col_map, field->field_index);
2321
2433
        }
2322
2434
 
2323
2435
        if (key_length > XT_INDEX_MAX_KEY_SIZE)
2404
2516
 
2405
2517
xtPublic void myxt_setup_dictionary(XTThreadPtr self, XTDictionaryPtr dic)
2406
2518
{
2407
 
        STRUCT_TABLE    *my_tab = dic->dic_my_table;
 
2519
        TABLE   *my_tab = dic->dic_my_table;
2408
2520
        u_int   field_count;
2409
2521
        u_int   var_field_count = 0;
2410
2522
        u_int   varchar_field_count = 0;
2421
2533
        u_int   dic_rec_size;
2422
2534
        xtBool  dic_rec_fixed;
2423
2535
        Field   *curr_field;
2424
 
        Field * const *field;
 
2536
        Field   **field;
2425
2537
 
2426
2538
        /* How many columns are required for all indexes. */
2427
2539
        KeyInfo                         *index;
2433
2545
#endif
2434
2546
 
2435
2547
        dic->dic_ind_cols_req = 0;
2436
 
        for (uint i=0; i<GET_TABLE_SHARE(my_tab)->keys; i++) {
2437
 
                index = &my_tab->getKeyInfo(i);
 
2548
        for (uint i=0; i<TS(my_tab)->keys; i++) {
 
2549
                index = &my_tab->key_info[i];
2438
2550
 
2439
2551
                key_part_end = index->key_part + index->key_parts;
2440
2552
                for (key_part = index->key_part; key_part != key_part_end; key_part++) {
2441
2553
                        curr_field = key_part->field;
2442
2554
 
2443
 
                        if ((u_int) curr_field->position()+1 > dic->dic_ind_cols_req)
2444
 
                                dic->dic_ind_cols_req = curr_field->position()+1;
 
2555
                        if ((u_int) curr_field->field_index+1 > dic->dic_ind_cols_req)
 
2556
                                dic->dic_ind_cols_req = curr_field->field_index+1;
2445
2557
                }
2446
2558
        }
2447
2559
 
2448
2560
        /* We will work out how many columns are required for all blobs: */
2449
2561
        dic->dic_blob_cols_req = 0;     
2450
2562
        field_count = 0;
2451
 
        for (field=GET_TABLE_FIELDS(my_tab); (curr_field = *field); field++) {
 
2563
        for (field=my_tab->field; (curr_field = *field); field++) {
2452
2564
                field_count++;
2453
2565
                min_data_size = curr_field->key_length();
2454
2566
                max_data_size = curr_field->key_length();
2478
2590
                                else
2479
2591
                                        max_ave_row_size = 200;
2480
2592
                                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;
 
2593
                                if ((u_int) curr_field->field_index+1 > dic->dic_blob_cols_req)
 
2594
                                        dic->dic_blob_cols_req = curr_field->field_index+1;
2483
2595
                                dic->dic_blob_count++;
2484
2596
                                xt_realloc(self, (void **) &dic->dic_blob_cols, sizeof(Field *) * dic->dic_blob_count);
2485
2597
                                dic->dic_blob_cols[dic->dic_blob_count-1] = curr_field;
2559
2671
 
2560
2672
        if (dic->dic_def_ave_row_size) {
2561
2673
                /* The average row size has been set: */
2562
 
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + GET_TABLE_SHARE(my_tab)->getRecordLength();
 
2674
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + TS(my_tab)->reclength;
2563
2675
 
2564
2676
                /* The conditions for a fixed record are: */
2565
 
                if (dic->dic_def_ave_row_size >= (xtWord8) GET_TABLE_SHARE(my_tab)->getRecordLength() &&
 
2677
                if (dic->dic_def_ave_row_size >= (xtWord8) TS(my_tab)->reclength &&
2566
2678
                        dic_rec_size <= XT_TAB_MAX_FIX_REC_LENGTH &&
2567
2679
                        !blob_field_count) {
2568
2680
                        dic_rec_fixed = TRUE;
2588
2700
                 * we handle these rows as fixed size rows.
2589
2701
                 * Fixed size rows use the internal MySQL format.
2590
2702
                 */
2591
 
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + GET_TABLE_SHARE(my_tab)->getRecordLength();
 
2703
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + TS(my_tab)->reclength;
2592
2704
                /* Fixed length records must be less than 16K in size,
2593
2705
                 * have an average size which is very close (20%) to the maximum size or
2594
2706
                 * be less than a minimum size,
2659
2771
                 * index columns!
2660
2772
                 */              
2661
2773
                if (field_count == dic->dic_ind_cols_req)
2662
 
                        dic->dic_ind_rec_len = GET_TABLE_SHARE(my_tab)->getRecordLength();
 
2774
                        dic->dic_ind_rec_len = TS(my_tab)->reclength;
2663
2775
                else {
2664
 
                        field=GET_TABLE_FIELDS(my_tab);
 
2776
                        field=my_tab->field;
2665
2777
                        
2666
2778
                        curr_field = field[dic->dic_ind_cols_req];
2667
 
                        dic->dic_ind_rec_len = curr_field->offset(my_tab->getDefaultValues());
 
2779
#if MYSQL_VERSION_ID < 50114
 
2780
                        dic->dic_ind_rec_len = curr_field->offset();
 
2781
#else
 
2782
                        dic->dic_ind_rec_len = curr_field->offset(curr_field->table->record[0]);
 
2783
#endif
2668
2784
                }
2669
2785
        }
2670
2786
 
2679
2795
        if (!dic_rec_fixed) {
2680
2796
                xtWord8 max_rec_size = offsetof(XTTabRecExt, re_data);
2681
2797
 
2682
 
                for (Field * const *f=GET_TABLE_FIELDS(my_tab); (curr_field = *f); f++) {
 
2798
                for (Field **f=my_tab->field; (curr_field = *f); f++) {
2683
2799
                        max_data_size = curr_field->key_length();
2684
2800
                        enum_field_types tno = curr_field->type();
2685
2801
                        if (tno == MYSQL_TYPE_BLOB)
2699
2815
                ASSERT(dic->dic_fix_col_count < dic->dic_no_of_cols);
2700
2816
        }
2701
2817
 
2702
 
        dic->dic_key_count = GET_TABLE_SHARE(my_tab)->keys;
2703
 
        dic->dic_mysql_buf_size = GET_TABLE_SHARE(my_tab)->rec_buff_length;
2704
 
        dic->dic_mysql_rec_size = GET_TABLE_SHARE(my_tab)->getRecordLength();
 
2818
        dic->dic_key_count = TS(my_tab)->keys;
 
2819
        dic->dic_mysql_buf_size = TS(my_tab)->rec_buff_length;
 
2820
        dic->dic_mysql_rec_size = TS(my_tab)->reclength;
2705
2821
}
2706
2822
 
2707
2823
static u_int my_get_best_superset(XTThreadPtr XT_UNUSED(self), XTDictionaryPtr dic, XTIndexPtr ind)
2731
2847
 */
2732
2848
xtPublic xtBool myxt_load_dictionary(XTThreadPtr self, XTDictionaryPtr dic, XTDatabaseHPtr db, XTPathStrPtr tab_path)
2733
2849
{
2734
 
        STRUCT_TABLE *my_tab;
 
2850
        TABLE *my_tab;
2735
2851
 
2736
2852
        if (!(my_tab = my_open_table(self, db, tab_path, dic->dic_table_type)))
2737
2853
                return FAILED;
2738
2854
        dic->dic_my_table = my_tab;
2739
2855
#ifdef DRIZZLED
2740
 
        dic->dic_def_ave_row_size = (xtWord8) GET_TABLE_SHARE(my_tab)->getTableProto()->options().avg_row_length();
 
2856
        dic->dic_def_ave_row_size = (xtWord8) my_tab->s->getTableProto()->options().avg_row_length();
2741
2857
#else
2742
 
        dic->dic_def_ave_row_size = (xtWord8) GET_TABLE_SHARE(my_tab)->avg_row_length;
 
2858
        dic->dic_def_ave_row_size = (xtWord8) my_tab->s->avg_row_length;
2743
2859
#endif
2744
2860
        myxt_setup_dictionary(self, dic);
2745
 
        dic->dic_keys = (XTIndexPtr *) xt_calloc(self, sizeof(XTIndexPtr) * GET_TABLE_SHARE(my_tab)->keys);
2746
 
        for (uint i=0; i<GET_TABLE_SHARE(my_tab)->keys; i++)
2747
 
                dic->dic_keys[i] = my_create_index(self, my_tab, i, &my_tab->getKeyInfo(i));
 
2861
        dic->dic_keys = (XTIndexPtr *) xt_calloc(self, sizeof(XTIndexPtr) * TS(my_tab)->keys);
 
2862
        for (uint i=0; i<TS(my_tab)->keys; i++)
 
2863
                dic->dic_keys[i] = my_create_index(self, my_tab, i, &my_tab->key_info[i]);
2748
2864
 
2749
2865
        /* Check if any key is a subset of another: */
2750
2866
        for (u_int i=0; i<dic->dic_key_count; i++)
2869
2985
        }
2870
2986
}
2871
2987
 
2872
 
static char *my_type_to_string(XTThreadPtr self, Field *field, STRUCT_TABLE *XT_UNUSED(my_tab))
 
2988
static char *my_type_to_string(XTThreadPtr self, Field *field, TABLE *XT_UNUSED(my_tab))
2873
2989
{
2874
2990
        char            buffer[MAX_FIELD_WIDTH + 400];
2875
2991
        const char      *ptr;
2915
3031
        return xt_dup_string(self, buffer); // type.length()
2916
3032
}
2917
3033
 
2918
 
xtPublic XTDDTable *myxt_create_table_from_table(XTThreadPtr self, STRUCT_TABLE *my_tab)
 
3034
xtPublic XTDDTable *myxt_create_table_from_table(XTThreadPtr self, TABLE *my_tab)
2919
3035
{
2920
3036
        XTDDTable               *dd_tab;
2921
3037
        Field                   *curr_field;
2927
3043
        dd_tab->init(self);
2928
3044
        pushr_(my_free_dd_table, dd_tab);
2929
3045
 
2930
 
        for (Field * const *field=GET_TABLE_FIELDS(my_tab); (curr_field = *field); field++) {
 
3046
        for (Field **field=my_tab->field; (curr_field = *field); field++) {
2931
3047
                col = XTDDColumnFactory::createFromMySQLField(self, my_tab, curr_field);
2932
3048
                dd_tab->dt_cols.append(self, col);
2933
3049
        }
2934
3050
 
2935
 
        for (uint i=0; i<GET_TABLE_SHARE(my_tab)->keys; i++) {
 
3051
        for (uint i=0; i<TS(my_tab)->keys; i++) {
2936
3052
                if (!(ind = (XTDDIndex *) new XTDDIndex(XT_DD_UNKNOWN)))
2937
3053
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
2938
3054
                dd_tab->dt_indexes.append(self, ind);
2939
3055
                ind->co_table = dd_tab;
2940
3056
                ind->in_index = i;
2941
 
                ha_create_dd_index(self, ind, &my_tab->getKeyInfo(i));
 
3057
                ha_create_dd_index(self, ind, &my_tab->key_info[i]);
2942
3058
        }
2943
3059
 
2944
3060
        popr_(); // my_free_dd_table(dd_tab)
2950
3066
 * MySQL CHARACTER UTILITIES
2951
3067
 */
2952
3068
 
2953
 
xtPublic void myxt_static_convert_identifier(XTThreadPtr XT_UNUSED(self), MX_CONST_CHARSET_INFO *cs, char *from, char *to, size_t to_len)
 
3069
xtPublic void myxt_static_convert_identifier(XTThreadPtr XT_UNUSED(self), MX_CHARSET_INFO *cs, char *from, char *to, size_t to_len)
2954
3070
{
2955
3071
#ifdef DRIZZLED
2956
 
        ((void)cs);
 
3072
        ((void *)cs);
2957
3073
         xt_strcpy(to_len, to, from);
2958
3074
#else
2959
3075
        uint errors;
2971
3087
}
2972
3088
 
2973
3089
// cs == current_thd->charset()
2974
 
xtPublic char *myxt_convert_identifier(XTThreadPtr self, MX_CONST_CHARSET_INFO *cs, char *from)
 
3090
xtPublic char *myxt_convert_identifier(XTThreadPtr self, MX_CHARSET_INFO *cs, char *from)
2975
3091
{
2976
3092
#ifdef DRIZZLED
2977
3093
        char *to = xt_dup_string(self, from);
2978
 
        ((void)cs);
 
3094
        ((void *)cs);
2979
3095
#else
2980
3096
        uint    errors;
2981
3097
        u_int   len;
3030
3146
 
3031
3147
xtPublic void myxt_static_convert_file_name(char *from, char *to, size_t to_len)
3032
3148
{
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;
 
3149
        filename_to_tablename(from, to, to_len);
3037
3150
}
3038
3151
 
3039
3152
xtPublic int myxt_strcasecmp(char * a, char *b)
3041
3154
        return my_strcasecmp(&my_charset_utf8_general_ci, a, b);
3042
3155
}
3043
3156
 
3044
 
xtPublic int myxt_isspace(MX_CONST_CHARSET_INFO *cs, char a)
 
3157
xtPublic int myxt_isspace(MX_CHARSET_INFO *cs, char a)
3045
3158
{
3046
3159
        return my_isspace(cs, a);
3047
3160
}
3048
3161
 
3049
 
xtPublic int myxt_ispunct(MX_CONST_CHARSET_INFO *cs, char a)
 
3162
xtPublic int myxt_ispunct(MX_CHARSET_INFO *cs, char a)
3050
3163
{
3051
3164
        return my_ispunct(cs, a);
3052
3165
}
3053
3166
 
3054
 
xtPublic int myxt_isdigit(MX_CONST_CHARSET_INFO *cs, char a)
 
3167
xtPublic int myxt_isdigit(MX_CHARSET_INFO *cs, char a)
3055
3168
{
3056
3169
        return my_isdigit(cs, a);
3057
3170
}
3058
3171
 
3059
 
xtPublic MX_CONST_CHARSET_INFO *myxt_getcharset(bool convert)
 
3172
xtPublic MX_CHARSET_INFO *myxt_getcharset(bool convert)
3060
3173
{
3061
3174
        if (convert) {
3062
3175
                THD *thd = current_thd;
3063
3176
 
3064
3177
                if (thd)
3065
 
                        return (MX_CHARSET_INFO *)thd->charset();
 
3178
                        return (MX_CHARSET_INFO *)thd_charset(thd);
3066
3179
        }
3067
3180
        return (MX_CHARSET_INFO *)&my_charset_utf8_general_ci;
3068
3181
}
3081
3194
xtPublic void *myxt_create_thread()
3082
3195
{
3083
3196
#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;
 
3197
        return (void *) 1;
3098
3198
#else
3099
3199
        THD *new_thd;
3100
3200
 
3172
3272
}
3173
3273
 
3174
3274
#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();
 
3275
xtPublic void myxt_destroy_thread(void *, xtBool)
 
3276
{
 
3277
}
 
3278
 
 
3279
xtPublic void myxt_delete_remaining_thread()
 
3280
{
3183
3281
}
3184
3282
#else
3185
3283
xtPublic void myxt_destroy_thread(void *thread, xtBool end_threads)
3208
3306
        if (end_threads)
3209
3307
                my_thread_end();
3210
3308
}
3211
 
#endif
3212
3309
 
3213
3310
xtPublic void myxt_delete_remaining_thread()
3214
3311
{
3217
3314
        if ((thd = current_thd))
3218
3315
                myxt_destroy_thread((void *) thd, TRUE);
3219
3316
}
 
3317
#endif
3220
3318
 
3221
3319
xtPublic XTThreadPtr myxt_get_self()
3222
3320
{
3242
3340
#ifdef UNUSED_CODE
3243
3341
static void mx_put_int(TABLE *table, int column, int value)
3244
3342
{
3245
 
        GET_TABLE_FIELDS(table)[column]->store(value, false);
 
3343
        table->field[column]->store(value, false);
3246
3344
}
3247
3345
 
3248
3346
static void mx_put_real8(TABLE *table, int column, xtReal8 value)
3249
3347
{
3250
 
        GET_TABLE_FIELDS(table)[column]->store(value);
 
3348
        table->field[column]->store(value);
3251
3349
}
3252
3350
 
3253
3351
static void mx_put_string(TABLE *table, int column, const char *string, u_int len, charset_info_st *charset)
3254
3352
{
3255
 
        GET_TABLE_FIELDS(table)[column]->store(string, len, charset);
 
3353
        table->field[column]->store(string, len, charset);
3256
3354
}
3257
3355
#endif
3258
3356
 
3259
3357
static void mx_put_u_llong(TABLE *table, int column, u_llong value)
3260
3358
{
3261
 
        GET_TABLE_FIELDS(table)[column]->store(value, false);
 
3359
        table->field[column]->store(value, false);
3262
3360
}
3263
3361
 
3264
3362
static void mx_put_string(TABLE *table, int column, const char *string, charset_info_st *charset)
3265
3363
{
3266
 
        GET_TABLE_FIELDS(table)[column]->store(string, strlen(string), charset);
 
3364
        table->field[column]->store(string, strlen(string), charset);
3267
3365
}
3268
3366
 
3269
3367
xtPublic int myxt_statistics_fill_table(XTThreadPtr self, void *th, void *ta, void *, MX_CONST void *ch)
3361
3459
 
3362
3460
static void myxt_bitmap_init(XTThreadPtr self, MX_BITMAP *map, u_int n_bits)
3363
3461
{
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
3462
        my_bitmap_map   *buf;
3371
3463
    uint                        size_in_bytes = (((n_bits) + 31) / 32) * 4;
 
3464
 
3372
3465
        buf = (my_bitmap_map *) xt_malloc(self, size_in_bytes);
 
3466
 
 
3467
#ifdef DRIZZLED
 
3468
        map->init(buf, n_bits);
 
3469
#else
3373
3470
        map->bitmap= buf;
3374
3471
        map->n_bits= n_bits;
3375
3472
        create_last_word_mask(map);
3380
3477
static void myxt_bitmap_free(XTThreadPtr self, MX_BITMAP *map)
3381
3478
{
3382
3479
#ifdef DRIZZLED
3383
 
    (void) self;
3384
 
    if (map->empty())
3385
 
        map->clear();
3386
 
    delete map;
 
3480
        my_bitmap_map *buf = map->getBitmap();
 
3481
        if (buf)
 
3482
                xt_free(self, buf);
 
3483
        map->setBitmap(NULL);
3387
3484
#else
3388
3485
        if (map->bitmap) {
3389
3486
                xt_free(self, map->bitmap);
3397
3494
 * XTDDColumnFactory methods
3398
3495
 */
3399
3496
 
3400
 
XTDDColumn *XTDDColumnFactory::createFromMySQLField(XTThread *self, STRUCT_TABLE *my_tab, Field *field)
 
3497
XTDDColumn *XTDDColumnFactory::createFromMySQLField(XTThread *self, TABLE *my_tab, Field *field)
3401
3498
{
3402
3499
        XTDDEnumerableColumn *en_col;
3403
3500
        XTDDColumn *col;
3452
3549
#ifdef DRIZZLED
3453
3550
        static std::string plugin_name("PBXT");
3454
3551
 
3455
 
        while (!self->t_quit && !module::Registry::singleton().find(plugin_name))
 
3552
        while (!self->t_quit && !Registry::singleton().find(plugin_name))
3456
3553
                xt_sleep_milli_second(1);
3457
3554
#else
3458
3555
        while(!self->t_quit && (pbxt_hton->slot >= total_ha))