~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-21 19:32:12 UTC
  • mfrom: (1531.1.5 trunk)
  • Revision ID: brian@gaz-20100521193212-1qauz3vvdqmlh77n
Merge Paul's work to use TableShare

Show diffs side-by-side

added added

removed removed

Lines of Context:
604
604
 * null_ptr refers to my buffer. If I cannot, then I
605
605
 * cannot use the set_notnull() method.
606
606
 */
607
 
static void mx_set_notnull_in_record(Field *field, char *record)
 
607
static void mx_set_notnull_in_record(STRUCT_TABLE *table, Field *field, char *record)
608
608
{
609
 
        if (field->null_ptr)
610
 
                record[(uint) (field->null_ptr - (uchar *) field->table->record[0])] &= (uchar) ~field->null_bit;
 
609
#ifdef DRIZZLED
 
610
        if (field->null_ptr)
 
611
                record[(uint) (field->null_ptr - (uchar *) table->default_values)] &= (uchar) ~field->null_bit;
 
612
#else
 
613
        ASSERT(table == field->table);
 
614
        if (field->null_ptr)
 
615
                record[(uint) (field->null_ptr - (uchar *) table->record[0])] &= (uchar) ~field->null_bit;
 
616
#endif
611
617
}
612
618
 
613
 
static xtBool mx_is_null_in_record(Field *field, char *record)
 
619
static xtBool mx_is_null_in_record(STRUCT_TABLE *table, Field *field, char *record)
614
620
{
615
621
        if (field->null_ptr) {
616
 
                if (record[(uint) (field->null_ptr - (uchar *) field->table->record[0])] & (uchar) field->null_bit)
617
 
                        return TRUE;
 
622
#ifdef DRIZZLED
 
623
                if (record[(uint) (field->null_ptr - (uchar *) table->default_values)] & (uchar) field->null_bit)
 
624
                        return TRUE;
 
625
#else
 
626
                ASSERT(table == field->table);
 
627
                if (record[(uint) (field->null_ptr - (uchar *) table->record[0])] & (uchar) field->null_bit)
 
628
                        return TRUE;
 
629
#endif
618
630
        }
619
631
        return FALSE;
620
632
}
624
636
 * method that just returns the byte length and
625
637
 * pointer to the data in a row.
626
638
 */
627
 
static char *mx_get_length_and_data(Field *field, char *dest, xtWord4 *len)
 
639
static char *mx_get_length_and_data(STRUCT_TABLE *table, Field *field, char *dest, xtWord4 *len)
628
640
{
629
641
        char *from;
630
642
        
631
 
#if MYSQL_VERSION_ID < 50114
632
 
        from = dest + field->offset();
 
643
#ifdef DRIZZLED
 
644
        from = dest + field->offset(table->default_values);
633
645
#else
634
 
        from = dest + field->offset(field->table->record[0]);
 
646
        ASSERT(table == field->table);
 
647
        from = dest + field->offset(table->record[0]);
635
648
#endif
636
649
        switch (field->real_type()) {
637
650
#ifndef DRIZZLED
654
667
                        field->ptr = save;                                      // Restore org row pointer
655
668
                        */
656
669
 
657
 
                        xtWord4 packlength = ((Field_blob *) field)->pack_length() - field->table->s->blob_ptr_size;
 
670
                        xtWord4 packlength = ((Field_blob *) field)->pack_length_no_ptr();
 
671
 
658
672
                        memcpy(&data, ((char *) from)+packlength, sizeof(char*));
659
673
                        
660
 
                        *len = ((Field_blob *) field)->get_length((byte *) from);
 
674
                        //*len = ((Field_blob *) field)->get_length((byte *) from);
 
675
                        *len = ((Field_blob *) field)->get_length((byte *) from, packlength, GET_TABLE_SHARE(table)->db_low_byte_first);
661
676
                        return data;
662
677
                }
663
678
#ifndef DRIZZLED
744
759
 * bug number 154 in the MySQL bug database: GROUP BY
745
760
 * and DISTINCT could treat NULL values inequal".
746
761
 */
747
 
static void mx_set_length_and_data(Field *field, char *dest, xtWord4 len, char *data)
 
762
static void mx_set_length_and_data(STRUCT_TABLE *table, Field *field, char *dest, xtWord4 len, char *data)
748
763
{
749
764
        char *from;
750
765
        
751
 
#if MYSQL_VERSION_ID < 50114
752
 
        from = dest + field->offset();
 
766
#ifdef DRIZZLED
 
767
        from = dest + field->offset(table->default_values);
753
768
#else
754
 
        from = dest + field->offset(field->table->record[0]);
 
769
        ASSERT(table == field->table);
 
770
        from = dest + field->offset(table->record[0]);
755
771
#endif
756
772
        switch (field->real_type()) {
757
773
#ifndef DRIZZLED
768
784
                        ((Field_blob *) field)->set_ptr(len, data);
769
785
                        field->ptr = save;                                      // Restore org row pointer
770
786
                        */
771
 
                        xtWord4 packlength = ((Field_blob *) field)->pack_length() - field->table->s->blob_ptr_size;
 
787
                        xtWord4 packlength = ((Field_blob *) field)->pack_length_no_ptr();
772
788
 
773
 
                        ((Field_blob *) field)->store_length((byte *) from, packlength, len);
 
789
                        ((Field_blob *) field)->store_length((byte *) from, packlength, len, GET_TABLE_SHARE(table)->db_low_byte_first);
774
790
                        memcpy_fixed(((char *) from)+packlength, &data, sizeof(char*));
775
791
 
776
792
                        if (data)
777
 
                                mx_set_notnull_in_record(field, dest);
 
793
                                mx_set_notnull_in_record(table, field, dest);
778
794
                        return;
779
795
                }
780
796
#ifndef DRIZZLED
781
797
                case MYSQL_TYPE_STRING:
782
798
                        if (data) {
783
 
                                mx_set_notnull_in_record(field, dest);
 
799
                                mx_set_notnull_in_record(table, field, dest);
784
800
                                memcpy(from, data, len);
785
801
                        }
786
802
                        else
792
808
                case MYSQL_TYPE_VAR_STRING:
793
809
                        int2store(from, len);
794
810
                        if (data) {
795
 
                                mx_set_notnull_in_record(field, dest);
 
811
                                mx_set_notnull_in_record(table, field, dest);
796
812
                                memcpy(from+HA_KEY_BLOB_LENGTH, data, len);
797
813
                        }
798
814
                        return;
803
819
                        else
804
820
                                int2store(from, len);
805
821
                        if (data) {
806
 
                                mx_set_notnull_in_record(field, dest);
 
822
                                mx_set_notnull_in_record(table, field, dest);
807
823
                                memcpy(from+((Field_varstring *) field)->length_bytes, data, len);
808
824
                        }
809
825
                        return;
843
859
        }
844
860
 
845
861
        if (data) {
846
 
                mx_set_notnull_in_record(field, dest);
 
862
                mx_set_notnull_in_record(table, field, dest);
847
863
                memcpy(from, data, len);
848
864
        }
849
865
        else
863
879
xtPublic void myxt_set_default_row_from_key(XTOpenTablePtr ot, XTIndexPtr ind, xtWord1 *record)
864
880
{
865
881
        XTTableHPtr             tab = ot->ot_table;
866
 
        TABLE                   *table = tab->tab_dic.dic_my_table;
 
882
        STRUCT_TABLE    *table = tab->tab_dic.dic_my_table;
867
883
        XTIndexSegRec   *keyseg = ind->mi_seg;
868
884
 
869
885
        xt_lock_mutex_ns(&tab->tab_dic_field_lock);
871
887
        for (u_int i=0; i<ind->mi_seg_count; i++, keyseg++) {
872
888
                
873
889
                u_int col_idx = keyseg->col_idx;
874
 
                Field *field = table->field[col_idx];
 
890
                Field *field = GET_TABLE_FIELDS(table)[col_idx];
875
891
                byte  *field_save = field->ptr;
876
892
 
877
 
                field->ptr = table->s->default_values + keyseg->start;
 
893
                field->ptr = GET_TABLE_SHARE(table)->default_values + keyseg->start;
878
894
                memcpy(record + keyseg->start, field->ptr, field->pack_length());
879
895
                record[keyseg->null_pos] &= ~keyseg->null_bit;
880
 
                record[keyseg->null_pos] |= table->s->default_values[keyseg->null_pos] & keyseg->null_bit;
 
896
                record[keyseg->null_pos] |= GET_TABLE_SHARE(table)->default_values[keyseg->null_pos] & keyseg->null_bit;
881
897
 
882
898
                field->ptr = field_save;
883
899
        }
1562
1578
 
1563
1579
xtPublic xtWord4 myxt_store_row_length(XTOpenTablePtr ot, char *rec_buff)
1564
1580
{
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;
 
1581
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
 
1582
        char                    *sdata;
 
1583
        xtWord4                 dlen;
 
1584
        xtWord4                 item_size;
 
1585
        xtWord4                 row_size = 0;
1570
1586
 
1571
 
        for (Field **field=table->field ; *field ; field++) {
 
1587
        for (Field **field=GET_TABLE_FIELDS(table); *field ; field++) {
1572
1588
                if ((*field)->is_null_in_record((const uchar *) rec_buff)) {
1573
1589
                        sdata = NULL;
1574
1590
                        dlen = 0;
1575
1591
                        item_size = 1;
1576
1592
                }
1577
1593
                else {
1578
 
                        sdata = mx_get_length_and_data(*field, rec_buff, &dlen);
 
1594
                        sdata = mx_get_length_and_data(table, *field, rec_buff, &dlen);
1579
1595
                        if (!dlen) {
1580
1596
                                /* Empty, but not null (blobs may return NULL, when
1581
1597
                                 * length is 0.
1600
1616
 
1601
1617
xtPublic xtWord4 myxt_store_row_data(XTOpenTablePtr ot, xtWord4 row_size, char *rec_buff)
1602
1618
{
1603
 
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
1604
 
        char    *sdata;
1605
 
        xtWord4 dlen;
1606
 
        xtWord4 item_size;
 
1619
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
 
1620
        char                    *sdata;
 
1621
        xtWord4                 dlen;
 
1622
        xtWord4                 item_size;
1607
1623
 
1608
 
        for (Field **field=table->field ; *field ; field++) {
1609
 
                if ((*field)->is_null_in_record((const uchar *) rec_buff)) {
 
1624
        for (Field **field=GET_TABLE_FIELDS(table); *field; field++) {
 
1625
                if (mx_is_null_in_record(table, *field, rec_buff)) {
1610
1626
                        sdata = NULL;
1611
1627
                        dlen = 0;
1612
1628
                        item_size = 1;
1613
1629
                }
1614
1630
                else {
1615
 
                        sdata = mx_get_length_and_data(*field, rec_buff, &dlen);
 
1631
                        sdata = mx_get_length_and_data(table, *field, rec_buff, &dlen);
1616
1632
                        if (!dlen) {
1617
1633
                                /* Empty, but not null (blobs may return NULL, when
1618
1634
                                 * length is 0.
1728
1744
/* Unload from PBXT variable length format to the MySQL row format. */
1729
1745
xtPublic xtWord4 myxt_load_row_data(XTOpenTablePtr ot, xtWord1 *source_buf, xtWord1 *dest_buff, u_int col_cnt)
1730
1746
{
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;
 
1747
        xtWord1                 *input_buf = source_buf;
 
1748
        STRUCT_TABLE    *table;
 
1749
        xtWord4                 len;
 
1750
        Field                   *curr_field;
 
1751
        xtBool                  is_null;
 
1752
        u_int                   i = 0;
1737
1753
 
1738
1754
        if (!(table = ot->ot_table->tab_dic.dic_my_table)) {
1739
1755
                xt_register_taberr(XT_REG_CONTEXT, XT_ERR_NO_DICTIONARY, ot->ot_table->tab_name);
1745
1761
         * have the SQL NULL bit set unless it
1746
1762
         * is a nullable column with a non-NULL value".
1747
1763
         */
1748
 
        memset(dest_buff, 0xFF, table->s->null_bytes);
1749
 
        for (Field **field=table->field ; *field && (!col_cnt || i<col_cnt); field++, i++) {
 
1764
        memset(dest_buff, 0xFF, GET_TABLE_SHARE(table)->null_bytes);
 
1765
        for (Field **field=GET_TABLE_FIELDS(table); *field && (!col_cnt || i<col_cnt); field++, i++) {
1750
1766
                curr_field = *field;
1751
1767
                is_null = FALSE;
1752
1768
                switch (*source_buf) {
1778
1794
                }
1779
1795
 
1780
1796
                if (is_null)
1781
 
                        mx_set_length_and_data(curr_field, (char *) dest_buff, 0, NULL);
 
1797
                        mx_set_length_and_data(table, curr_field, (char *) dest_buff, 0, NULL);
1782
1798
                else
1783
 
                        mx_set_length_and_data(curr_field, (char *) dest_buff, len, (char *) source_buf);
 
1799
                        mx_set_length_and_data(table, curr_field, (char *) dest_buff, len, (char *) source_buf);
1784
1800
 
1785
1801
                source_buf += len;
1786
1802
        }
1794
1810
 
1795
1811
xtPublic xtBool myxt_find_column(XTOpenTablePtr ot, u_int *col_idx, const char *col_name)
1796
1812
{
1797
 
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
1798
 
        u_int   i=0;
 
1813
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
 
1814
        u_int                   i=0;
1799
1815
 
1800
 
        for (Field **field=table->field; *field; field++, i++) {
 
1816
        for (Field **field=GET_TABLE_FIELDS(table); *field; field++, i++) {
1801
1817
                if (!my_strcasecmp(system_charset_info, (*field)->field_name, col_name)) {
1802
1818
                        *col_idx = i;
1803
1819
                        return OK;
1808
1824
 
1809
1825
xtPublic void myxt_get_column_name(XTOpenTablePtr ot, u_int col_idx, u_int len, char *col_name)
1810
1826
{
1811
 
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
1812
 
        Field   *field;
 
1827
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
 
1828
        Field                   *field;
1813
1829
 
1814
 
        field = table->field[col_idx];
 
1830
        field = GET_TABLE_FIELDS(table)[col_idx];
1815
1831
        xt_strcpy(len, col_name, field->field_name);
1816
1832
}
1817
1833
 
1818
1834
xtPublic void myxt_get_column_as_string(XTOpenTablePtr ot, char *buffer, u_int col_idx, u_int len, char *value)
1819
1835
{
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);
 
1836
        XTTableHPtr             tab = ot->ot_table;
 
1837
        XTThreadPtr             self = ot->ot_thread;
 
1838
        STRUCT_TABLE    *table = tab->tab_dic.dic_my_table;
 
1839
        Field                   *field = GET_TABLE_FIELDS(table)[col_idx];
 
1840
        char                    buf_val[MAX_FIELD_WIDTH];
 
1841
        String                  val(buf_val, sizeof(buf_val), &my_charset_bin);
1826
1842
 
1827
 
        if (mx_is_null_in_record(field, buffer))
 
1843
        if (mx_is_null_in_record(table, field, buffer))
1828
1844
                xt_strcpy(len, value, "NULL");
1829
1845
        else {
1830
1846
                byte    *save;
1831
1847
 
 
1848
#ifndef DRIZZLED
1832
1849
                /* Required by store() - or an assertion will fail: */
1833
1850
                if (table->read_set)
1834
1851
                        MX_BIT_SET(table->read_set, col_idx);
 
1852
#endif
1835
1853
 
1836
1854
                save = field->ptr;
1837
1855
                xt_lock_mutex(self, &tab->tab_dic_field_lock);
1838
1856
                pushr_(xt_unlock_mutex, &tab->tab_dic_field_lock);
1839
 
#if MYSQL_VERSION_ID < 50114
1840
 
                field->ptr = (byte *) buffer + field->offset();
 
1857
#ifdef DRIZZLED
 
1858
                field->ptr = (byte *) buffer + field->offset(table->default_values);
1841
1859
#else
1842
1860
                field->ptr = (byte *) buffer + field->offset(field->table->record[0]);
1843
1861
#endif
1850
1868
 
1851
1869
xtPublic xtBool myxt_set_column(XTOpenTablePtr ot, char *buffer, u_int col_idx, const char *value, u_int len)
1852
1870
{
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;
 
1871
        XTTableHPtr             tab = ot->ot_table;
 
1872
        XTThreadPtr             self = ot->ot_thread;
 
1873
        STRUCT_TABLE    *table = tab->tab_dic.dic_my_table;
 
1874
        Field                   *field = GET_TABLE_FIELDS(table)[col_idx];
 
1875
        byte                    *save;
 
1876
        int                             error;
1859
1877
 
 
1878
#ifndef DRIZZLED
1860
1879
        /* Required by store() - or an assertion will fail: */
1861
1880
        if (table->write_set)
1862
1881
                MX_BIT_SET(table->write_set, col_idx);
 
1882
#endif
1863
1883
 
1864
 
        mx_set_notnull_in_record(field, buffer);
 
1884
        mx_set_notnull_in_record(table, field, buffer);
1865
1885
 
1866
1886
        save = field->ptr;
1867
1887
        xt_lock_mutex(self, &tab->tab_dic_field_lock);
1868
1888
        pushr_(xt_unlock_mutex, &tab->tab_dic_field_lock);
1869
 
#if MYSQL_VERSION_ID < 50114
1870
 
        field->ptr = (byte *) buffer + field->offset();
 
1889
#ifdef DRIZZLED
 
1890
        field->ptr = (byte *) buffer + field->offset(table->default_values);
1871
1891
#else
1872
1892
        field->ptr = (byte *) buffer + field->offset(field->table->record[0]);
1873
1893
#endif
1879
1899
 
1880
1900
xtPublic void myxt_get_column_data(XTOpenTablePtr ot, char *buffer, u_int col_idx, char **value, size_t *len)
1881
1901
{
1882
 
        TABLE   *table = ot->ot_table->tab_dic.dic_my_table;
1883
 
        Field   *field = table->field[col_idx];
1884
 
        char    *sdata;
1885
 
        xtWord4 dlen;
 
1902
        STRUCT_TABLE    *table = ot->ot_table->tab_dic.dic_my_table;
 
1903
        Field                   *field = GET_TABLE_FIELDS(table)[col_idx];
 
1904
        char                    *sdata;
 
1905
        xtWord4                 dlen;
1886
1906
 
1887
 
        sdata = mx_get_length_and_data(field, buffer, &dlen);
 
1907
        sdata = mx_get_length_and_data(table, field, buffer, &dlen);
1888
1908
        *value = sdata;
1889
1909
        *len = dlen;
1890
1910
}
1987
2007
 * MySQL Data Dictionary
1988
2008
 */
1989
2009
 
1990
 
#define TS(x)                                   (x)->s
1991
 
 
1992
 
static void my_close_table(TABLE *table)
 
2010
#ifdef DRIZZLED
 
2011
static void my_close_table(STRUCT_TABLE *share)
 
2012
{
 
2013
        delete share;
 
2014
}
 
2015
 
 
2016
/*
 
2017
 * This function returns NULL if the table cannot be opened 
 
2018
 * because this is not a MySQL thread.
 
2019
 */ 
 
2020
static STRUCT_TABLE *my_open_table(XTThreadPtr self, XTDatabaseHPtr XT_UNUSED(db), XTPathStrPtr tab_path, xtWord1 table_type)
 
2021
{
 
2022
        THD                     *thd = current_thd;
 
2023
        char            *tab_file_name;
 
2024
        char            database_name[XT_IDENTIFIER_NAME_SIZE];
 
2025
        char            tab_name[XT_IDENTIFIER_NAME_SIZE];
 
2026
        uint32_t        tab_name_len;   
 
2027
        TableShare      *share;
 
2028
        int                     error;
 
2029
 
 
2030
        /* If we have no MySQL thread, then we cannot open this table!
 
2031
         * What this means is the thread is probably the sweeper or the
 
2032
         * compactor.
 
2033
         */
 
2034
        if (!thd)
 
2035
                return NULL;
 
2036
 
 
2037
        tab_file_name = xt_last_name_of_path(tab_path->ps_path);
 
2038
        tab_name_len = filename_to_tablename(tab_file_name, tab_name, XT_IDENTIFIER_NAME_SIZE);
 
2039
 
 
2040
        xt_2nd_last_name_of_path(XT_IDENTIFIER_NAME_SIZE, database_name, tab_path->ps_path);
 
2041
 
 
2042
        TableIdentifier *ident = NULL;
 
2043
        
 
2044
        if (table_type == XT_TABLE_TYPE_TEMPORARY) {
 
2045
                std::string tmp_path(drizzle_tmpdir);
 
2046
                tmp_path.append("/");
 
2047
                tmp_path.append(tab_file_name);
 
2048
                ident = new TableIdentifier(database_name, tab_name, tmp_path);
 
2049
        }
 
2050
        else if (table_type == XT_TABLE_TYPE_STANDARD) {
 
2051
                ident = new TableIdentifier(
 
2052
                        std::string(database_name), 
 
2053
                        std::string(tab_name, tab_name_len), 
 
2054
                        message::Table::STANDARD);
 
2055
        }
 
2056
        else {
 
2057
                std::string n;
 
2058
                n.append(data_home);
 
2059
                n.append("/");
 
2060
                n.append(database_name);
 
2061
                n.append("/");
 
2062
                n.append(tab_file_name);
 
2063
                ident = new TableIdentifier(database_name, tab_name, n);
 
2064
        }
 
2065
        
 
2066
        share = new TableShare();
 
2067
        share->init();
 
2068
        if ((error = share->open_table_def(*thd, *ident))) {
 
2069
          xt_throw_sulxterr(XT_CONTEXT, XT_ERR_LOADING_MYSQL_DIC, tab_path->ps_path, (u_long) error);
 
2070
          delete ident;
 
2071
          return NULL;
 
2072
        }
 
2073
        delete ident;
 
2074
 
 
2075
        return share;
 
2076
}
 
2077
#else // DRIZZLED
 
2078
static void my_close_table(STRUCT_TABLE *table)
1993
2079
{
1994
2080
#ifdef DRIZZLED
1995
2081
#if 0 // Removed by Brian
2008
2094
 * This function returns NULL if the table cannot be opened 
2009
2095
 * because this is not a MySQL thread.
2010
2096
 */ 
2011
 
static TABLE *my_open_table(XTThreadPtr self, XTDatabaseHPtr XT_UNUSED(db), XTPathStrPtr tab_path, xtWord1 table_type)
 
2097
static STRUCT_TABLE *my_open_table(XTThreadPtr self, XTDatabaseHPtr XT_UNUSED(db), XTPathStrPtr tab_path, xtWord1 table_type)
2012
2098
{
2013
2099
        THD                     *thd = current_thd;
2014
2100
        char            path_buffer[PATH_MAX];
2176
2262
#endif
2177
2263
        return table;
2178
2264
}
 
2265
#endif // DRIZZLED
2179
2266
 
2180
2267
/*
2181
2268
static bool my_match_index(XTDDIndex *ind, KEY *index)
2258
2345
#define MX_OFFSETOF(x, y)               ((size_t)(&((x *) 8)->y) - 8)
2259
2346
 
2260
2347
/* Derived from ha_myisam::create and mi_create */
2261
 
static XTIndexPtr my_create_index(XTThreadPtr self, TABLE *table_arg, u_int idx, KeyInfo *index)
 
2348
static XTIndexPtr my_create_index(XTThreadPtr self, STRUCT_TABLE *table_arg, u_int idx, KeyInfo *index)
2262
2349
{
2263
2350
        XTIndexPtr                              ind;
2264
2351
        KeyPartInfo                     *key_part;
2278
2365
        xt_spinlock_init_with_autoname(self, &ind->mi_dirty_lock);
2279
2366
        ind->mi_index_no = idx;
2280
2367
        ind->mi_flags = (index->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL | HA_UNIQUE_CHECK));
2281
 
        ind->mi_low_byte_first = TS(table_arg)->db_low_byte_first;
 
2368
        ind->mi_low_byte_first = GET_TABLE_SHARE(table_arg)->db_low_byte_first;
2282
2369
        ind->mi_fix_key = TRUE;
2283
2370
        ind->mi_select_total = 0;
2284
2371
        ind->mi_subset_of = 0;
2285
 
        myxt_bitmap_init(self, &ind->mi_col_map, TS(table_arg)->fields);
 
2372
        myxt_bitmap_init(self, &ind->mi_col_map, GET_TABLE_SHARE(table_arg)->fields);
2286
2373
        
2287
2374
        ind->mi_seg_count = (uint) index->key_parts;
2288
2375
        key_part_end = index->key_part + index->key_parts;
2330
2417
                        key_length++;
2331
2418
                        seg->flag |= HA_NULL_PART;
2332
2419
                        seg->null_bit = field->null_bit;
 
2420
#ifdef DRIZZLED
 
2421
                        seg->null_pos = (uint) (field->null_ptr - (uchar*) table_arg->default_values);
 
2422
#else
2333
2423
                        seg->null_pos = (uint) (field->null_ptr - (uchar*) table_arg->record[0]);
 
2424
#endif
2334
2425
                }
2335
2426
                else {
2336
2427
                        seg->null_bit = 0;
2355
2446
                        ) {
2356
2447
                        seg->flag |= HA_BLOB_PART;
2357
2448
                        /* save number of bytes used to pack length */
2358
 
                        seg->bit_start = (uint) (field->pack_length() - TS(table_arg)->blob_ptr_size);
 
2449
                        seg->bit_start = (uint) ((Field_blob *) field)->pack_length_no_ptr();
2359
2450
                }
2360
2451
#ifndef DRIZZLED
2361
2452
                else if (field->type() == MYSQL_TYPE_BIT) {
2420
2511
#endif
2421
2512
                        )
2422
2513
                {
2423
 
                        Field   *tab_field = table_arg->field[key_part->fieldnr-1];
 
2514
                        Field   *tab_field = GET_TABLE_FIELDS(table_arg)[key_part->fieldnr-1];
2424
2515
                        u_int   field_len = tab_field->key_length();
2425
2516
 
2426
2517
                        if (key_part->length != field_len)
2516
2607
 
2517
2608
xtPublic void myxt_setup_dictionary(XTThreadPtr self, XTDictionaryPtr dic)
2518
2609
{
2519
 
        TABLE   *my_tab = dic->dic_my_table;
 
2610
        STRUCT_TABLE    *my_tab = dic->dic_my_table;
2520
2611
        u_int   field_count;
2521
2612
        u_int   var_field_count = 0;
2522
2613
        u_int   varchar_field_count = 0;
2545
2636
#endif
2546
2637
 
2547
2638
        dic->dic_ind_cols_req = 0;
2548
 
        for (uint i=0; i<TS(my_tab)->keys; i++) {
 
2639
        for (uint i=0; i<GET_TABLE_SHARE(my_tab)->keys; i++) {
2549
2640
                index = &my_tab->key_info[i];
2550
2641
 
2551
2642
                key_part_end = index->key_part + index->key_parts;
2560
2651
        /* We will work out how many columns are required for all blobs: */
2561
2652
        dic->dic_blob_cols_req = 0;     
2562
2653
        field_count = 0;
2563
 
        for (field=my_tab->field; (curr_field = *field); field++) {
 
2654
        for (field=GET_TABLE_FIELDS(my_tab); (curr_field = *field); field++) {
2564
2655
                field_count++;
2565
2656
                min_data_size = curr_field->key_length();
2566
2657
                max_data_size = curr_field->key_length();
2671
2762
 
2672
2763
        if (dic->dic_def_ave_row_size) {
2673
2764
                /* The average row size has been set: */
2674
 
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + TS(my_tab)->reclength;
 
2765
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + GET_TABLE_SHARE(my_tab)->reclength;
2675
2766
 
2676
2767
                /* The conditions for a fixed record are: */
2677
 
                if (dic->dic_def_ave_row_size >= (xtWord8) TS(my_tab)->reclength &&
 
2768
                if (dic->dic_def_ave_row_size >= (xtWord8) GET_TABLE_SHARE(my_tab)->reclength &&
2678
2769
                        dic_rec_size <= XT_TAB_MAX_FIX_REC_LENGTH &&
2679
2770
                        !blob_field_count) {
2680
2771
                        dic_rec_fixed = TRUE;
2700
2791
                 * we handle these rows as fixed size rows.
2701
2792
                 * Fixed size rows use the internal MySQL format.
2702
2793
                 */
2703
 
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + TS(my_tab)->reclength;
 
2794
                dic_rec_size = offsetof(XTTabRecFix, rf_data) + GET_TABLE_SHARE(my_tab)->reclength;
2704
2795
                /* Fixed length records must be less than 16K in size,
2705
2796
                 * have an average size which is very close (20%) to the maximum size or
2706
2797
                 * be less than a minimum size,
2771
2862
                 * index columns!
2772
2863
                 */              
2773
2864
                if (field_count == dic->dic_ind_cols_req)
2774
 
                        dic->dic_ind_rec_len = TS(my_tab)->reclength;
 
2865
                        dic->dic_ind_rec_len = GET_TABLE_SHARE(my_tab)->reclength;
2775
2866
                else {
2776
 
                        field=my_tab->field;
 
2867
                        field=GET_TABLE_FIELDS(my_tab);
2777
2868
                        
2778
2869
                        curr_field = field[dic->dic_ind_cols_req];
2779
 
#if MYSQL_VERSION_ID < 50114
2780
 
                        dic->dic_ind_rec_len = curr_field->offset();
 
2870
#ifdef DRIZZLED
 
2871
                        dic->dic_ind_rec_len = curr_field->offset(my_tab->default_values);
2781
2872
#else
2782
 
                        dic->dic_ind_rec_len = curr_field->offset(curr_field->table->record[0]);
 
2873
                        dic->dic_ind_rec_len = curr_field->offset(my_tab->record[0]);
2783
2874
#endif
2784
2875
                }
2785
2876
        }
2795
2886
        if (!dic_rec_fixed) {
2796
2887
                xtWord8 max_rec_size = offsetof(XTTabRecExt, re_data);
2797
2888
 
2798
 
                for (Field **f=my_tab->field; (curr_field = *f); f++) {
 
2889
                for (Field **f=GET_TABLE_FIELDS(my_tab); (curr_field = *f); f++) {
2799
2890
                        max_data_size = curr_field->key_length();
2800
2891
                        enum_field_types tno = curr_field->type();
2801
2892
                        if (tno == MYSQL_TYPE_BLOB)
2815
2906
                ASSERT(dic->dic_fix_col_count < dic->dic_no_of_cols);
2816
2907
        }
2817
2908
 
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;
 
2909
        dic->dic_key_count = GET_TABLE_SHARE(my_tab)->keys;
 
2910
        dic->dic_mysql_buf_size = GET_TABLE_SHARE(my_tab)->rec_buff_length;
 
2911
        dic->dic_mysql_rec_size = GET_TABLE_SHARE(my_tab)->reclength;
2821
2912
}
2822
2913
 
2823
2914
static u_int my_get_best_superset(XTThreadPtr XT_UNUSED(self), XTDictionaryPtr dic, XTIndexPtr ind)
2847
2938
 */
2848
2939
xtPublic xtBool myxt_load_dictionary(XTThreadPtr self, XTDictionaryPtr dic, XTDatabaseHPtr db, XTPathStrPtr tab_path)
2849
2940
{
2850
 
        TABLE *my_tab;
 
2941
        STRUCT_TABLE *my_tab;
2851
2942
 
2852
2943
        if (!(my_tab = my_open_table(self, db, tab_path, dic->dic_table_type)))
2853
2944
                return FAILED;
2854
2945
        dic->dic_my_table = my_tab;
2855
2946
#ifdef DRIZZLED
2856
 
        dic->dic_def_ave_row_size = (xtWord8) my_tab->s->getTableProto()->options().avg_row_length();
 
2947
        dic->dic_def_ave_row_size = (xtWord8) GET_TABLE_SHARE(my_tab)->getTableProto()->options().avg_row_length();
2857
2948
#else
2858
 
        dic->dic_def_ave_row_size = (xtWord8) my_tab->s->avg_row_length;
 
2949
        dic->dic_def_ave_row_size = (xtWord8) GET_TABLE_SHARE(my_tab)->avg_row_length;
2859
2950
#endif
2860
2951
        myxt_setup_dictionary(self, dic);
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++)
 
2952
        dic->dic_keys = (XTIndexPtr *) xt_calloc(self, sizeof(XTIndexPtr) * GET_TABLE_SHARE(my_tab)->keys);
 
2953
        for (uint i=0; i<GET_TABLE_SHARE(my_tab)->keys; i++)
2863
2954
                dic->dic_keys[i] = my_create_index(self, my_tab, i, &my_tab->key_info[i]);
2864
2955
 
2865
2956
        /* Check if any key is a subset of another: */
2985
3076
        }
2986
3077
}
2987
3078
 
2988
 
static char *my_type_to_string(XTThreadPtr self, Field *field, TABLE *XT_UNUSED(my_tab))
 
3079
static char *my_type_to_string(XTThreadPtr self, Field *field, STRUCT_TABLE *XT_UNUSED(my_tab))
2989
3080
{
2990
3081
        char            buffer[MAX_FIELD_WIDTH + 400];
2991
3082
        const char      *ptr;
3031
3122
        return xt_dup_string(self, buffer); // type.length()
3032
3123
}
3033
3124
 
3034
 
xtPublic XTDDTable *myxt_create_table_from_table(XTThreadPtr self, TABLE *my_tab)
 
3125
xtPublic XTDDTable *myxt_create_table_from_table(XTThreadPtr self, STRUCT_TABLE *my_tab)
3035
3126
{
3036
3127
        XTDDTable               *dd_tab;
3037
3128
        Field                   *curr_field;
3043
3134
        dd_tab->init(self);
3044
3135
        pushr_(my_free_dd_table, dd_tab);
3045
3136
 
3046
 
        for (Field **field=my_tab->field; (curr_field = *field); field++) {
 
3137
        for (Field **field=GET_TABLE_FIELDS(my_tab); (curr_field = *field); field++) {
3047
3138
                col = XTDDColumnFactory::createFromMySQLField(self, my_tab, curr_field);
3048
3139
                dd_tab->dt_cols.append(self, col);
3049
3140
        }
3050
3141
 
3051
 
        for (uint i=0; i<TS(my_tab)->keys; i++) {
 
3142
        for (uint i=0; i<GET_TABLE_SHARE(my_tab)->keys; i++) {
3052
3143
                if (!(ind = (XTDDIndex *) new XTDDIndex(XT_DD_UNKNOWN)))
3053
3144
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
3054
3145
                dd_tab->dt_indexes.append(self, ind);
3340
3431
#ifdef UNUSED_CODE
3341
3432
static void mx_put_int(TABLE *table, int column, int value)
3342
3433
{
3343
 
        table->field[column]->store(value, false);
 
3434
        GET_TABLE_FIELDS(table)[column]->store(value, false);
3344
3435
}
3345
3436
 
3346
3437
static void mx_put_real8(TABLE *table, int column, xtReal8 value)
3347
3438
{
3348
 
        table->field[column]->store(value);
 
3439
        GET_TABLE_FIELDS(table)[column]->store(value);
3349
3440
}
3350
3441
 
3351
3442
static void mx_put_string(TABLE *table, int column, const char *string, u_int len, charset_info_st *charset)
3352
3443
{
3353
 
        table->field[column]->store(string, len, charset);
 
3444
        GET_TABLE_FIELDS(table)[column]->store(string, len, charset);
3354
3445
}
3355
3446
#endif
3356
3447
 
3357
3448
static void mx_put_u_llong(TABLE *table, int column, u_llong value)
3358
3449
{
3359
 
        table->field[column]->store(value, false);
 
3450
        GET_TABLE_FIELDS(table)[column]->store(value, false);
3360
3451
}
3361
3452
 
3362
3453
static void mx_put_string(TABLE *table, int column, const char *string, charset_info_st *charset)
3363
3454
{
3364
 
        table->field[column]->store(string, strlen(string), charset);
 
3455
        GET_TABLE_FIELDS(table)[column]->store(string, strlen(string), charset);
3365
3456
}
3366
3457
 
3367
3458
xtPublic int myxt_statistics_fill_table(XTThreadPtr self, void *th, void *ta, void *, MX_CONST void *ch)
3494
3585
 * XTDDColumnFactory methods
3495
3586
 */
3496
3587
 
3497
 
XTDDColumn *XTDDColumnFactory::createFromMySQLField(XTThread *self, TABLE *my_tab, Field *field)
 
3588
XTDDColumn *XTDDColumnFactory::createFromMySQLField(XTThread *self, STRUCT_TABLE *my_tab, Field *field)
3498
3589
{
3499
3590
        XTDDEnumerableColumn *en_col;
3500
3591
        XTDDColumn *col;