[beginner question] select a row by primary key

KPATKOCTb <[email protected]>
Newsgroups gmane.comp.db.mysql.devel
Message-ID <[email protected]>
Just started to work with mysql internals, and I'm trying to access a row by primary key. 
The row is in fact found, as i can see in the debugger, but when i'm trying to access it with val_int or val_str I recieve a SIGSEGV from field.cc, ASSERT_COLUMN_MARKED_FOR_READ.
I don't think this matters, but i have mysqld version 5.1.56-debug-log for pc-linux-gnu on i686 (Source distribution).

That's the query, the effect of which i want to achieve:
mysql> select * from test.data where id=2793;
| 2793 | 56f9beb3bc4578b3bca40ede0408e2a3 |

That's is my code:

THD *thd = _current_thd();
TABLE_LIST tables;
tables.init_one_table("test","data", TL_READ);
simple_open_n_lock_tables(thd, &tables);
bool refresh = true;
TABLE *table = tables.table;
table->file->ha_index_init(0, 1);
KEY *index = table->key_info;
table->use_all_columns();

int key_len= index->key_part[0].store_length;
uchar* key_buf= (uchar*) thd->alloc(index->key_length);
bzero(key_buf, index->key_length);
int null_offset= table->field[0]->null_bit;
int4store(key_buf + null_offset, 2793);

table->file->index_read_last_map(table->record[0], key_buf, 1);
//table->file->index_read_map(table->record[0], key_buf, 1, HA_READ_KEY_EXACT); also tried that 

std::cerr << table->field[0]->val_int() << std::endl; //line 175 which fails


char rwpstr_buf[1024];
::String rwpstr(rwpstr_buf, sizeof(rwpstr_buf),&my_charset_bin);
Field *const fld = table->field[1];
fld->val_str(&rwpstr, &rwpstr); //if i comment out line 175, i'll get SIGSEGV on this line 
std::cerr << rwpstr_buf << std::endl;


The debugger:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb5128b70 (LWP 11766)]
0x08197f54 in bitmap_is_set (this=0x8639c78) at ../include/my_bitmap.h:141
141       return _bitmap_is_set(map,bit);
(gdb) bt
#0  0x08197f54 in bitmap_is_set (this=0x8607c80) at ../include/my_bitmap.h:141
#1  Field_long::val_int (this=0x8607c80) at field.cc:3723
#2  0xb51b649f in xFind (args=...) at xmysql.hpp:175
(gdb) frame 2
(gdb) p *((int*)key_buf)
$6 = 2793
(gdb) p table->field[1]->ptr
$10 = (uchar *) 0x8607f54 " "
(gdb) p table->field[1]->ptr[1]
$11 = 0 '\000'
(gdb) p table->field[1]->ptr[2]
$12 = 53 '5'
(gdb) p table->field[1]->ptr[3]
$13 = 54 '6'
(gdb) p table->field[1]->ptr[4]
$14 = 102 'f'
(gdb) p table->field[1]->ptr[5]
$15 = 57 '9'

So, as you can see, 56f9 is the first characters of second columnt of the row I searched for. So it's really found.

And that's field.cc, lines 3721-3724:
longlong Field_long::val_int(void)
{
  ASSERT_COLUMN_MARKED_FOR_READ;
  int32 j;


-- 
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.