OSDN Git Service

Initial commit of senna-1.1.2-fast.
[ludiafuncs/senna-1.1.2-fast.git] / bindings / mysql / mysql-5.1.15-beta.senna.2ind.diff
1 diff -Ndur ../mysql-5.1.15-beta.senna/include/my_pthread.h ./include/my_pthread.h
2 --- ../mysql-5.1.15-beta.senna/include/my_pthread.h     2007-01-30 17:34:03.000000000 +0900
3 +++ ./include/my_pthread.h      2007-02-26 23:22:42.000000000 +0900
4 @@ -680,6 +680,9 @@
5    gptr dbug;
6    char name[THREAD_NAME_SIZE+1];
7  #endif
8 +#ifdef ENABLE_SENNA
9 +  int sen_flags;
10 +#endif /* ENABLE_SENNA */
11  };
12  
13  extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
14 diff -Ndur ../mysql-5.1.15-beta.senna/libmysqld/filesort.cc ./libmysqld/filesort.cc
15 --- ../mysql-5.1.15-beta.senna/libmysqld/filesort.cc    2007-01-30 17:34:12.000000000 +0900
16 +++ ./libmysqld/filesort.cc     2007-02-26 23:22:42.000000000 +0900
17 @@ -1365,6 +1365,9 @@
18        }
19        if (sortorder->field->maybe_null())
20         length++;                               // Place for NULL marker
21 +#ifdef ENABLE_SENNA
22 +      my_thread_var->sen_flags |= 2;
23 +#endif /* ENABLE_SENNA */
24      }
25      else
26      {
27 diff -Ndur ../mysql-5.1.15-beta.senna/libmysqld/item_cmpfunc.cc ./libmysqld/item_cmpfunc.cc
28 --- ../mysql-5.1.15-beta.senna/libmysqld/item_cmpfunc.cc        2007-01-30 17:34:26.000000000 +0900
29 +++ ./libmysqld/item_cmpfunc.cc 2007-02-26 23:22:42.000000000 +0900
30 @@ -2402,6 +2402,22 @@
31    return 0;
32  }
33  
34 +#ifdef ENABLE_SENNA
35 +bool 
36 +Item_cond::needs_record()
37 +{
38 +  List_iterator_fast<Item> li(list);
39 +  Item *item;
40 +  while ((item=li++))
41 +  {
42 +    if (item->needs_record())
43 +    {
44 +      return true;
45 +    }
46 +  }
47 +  return false;
48 +}
49 +#endif /* ENABLE_SENNA */
50  
51  /*
52    Perform context analysis of an IN item tree
53 diff -Ndur ../mysql-5.1.15-beta.senna/libmysqld/item_func.cc ./libmysqld/item_func.cc
54 --- ../mysql-5.1.15-beta.senna/libmysqld/item_func.cc   2007-01-30 17:34:37.000000000 +0900
55 +++ ./libmysqld/item_func.cc    2007-02-26 23:22:42.000000000 +0900
56 @@ -4714,7 +4714,11 @@
57    for (keynr=0 ; keynr < table->s->keys ; keynr++)
58    {
59      if ((table->key_info[keynr].flags & HA_FULLTEXT) &&
60 -        (table->keys_in_use_for_query.is_set(keynr)))
61 +        ((table->keys_in_use_for_query.is_set(keynr))
62 +#ifdef ENABLE_SENNA
63 +        || my_thread_var->sen_flags
64 +#endif /* ENABLE_SENNA */
65 +        ))
66      {
67        ft_to_key[fts]=keynr;
68        ft_cnt[fts]=0;
69 diff -Ndur ../mysql-5.1.15-beta.senna/libmysqld/item_sum.cc ./libmysqld/item_sum.cc
70 --- ../mysql-5.1.15-beta.senna/libmysqld/item_sum.cc    2007-01-30 17:34:31.000000000 +0900
71 +++ ./libmysqld/item_sum.cc     2007-02-26 23:22:42.000000000 +0900
72 @@ -2444,6 +2444,9 @@
73      return TRUE;
74  
75    /* Create a table with an unique key over all parameters */
76 +#ifdef ENABLE_SENNA
77 +  my_thread_var->sen_flags |= 16;
78 +#endif /* ENABLE_SENNA */
79    for (uint i=0; i < arg_count ; i++)
80    {
81      Item *item=args[i];
82 diff -Ndur ../mysql-5.1.15-beta.senna/libmysqld/records.cc ./libmysqld/records.cc
83 --- ../mysql-5.1.15-beta.senna/libmysqld/records.cc     2007-01-30 17:34:12.000000000 +0900
84 +++ ./libmysqld/records.cc      2007-02-26 23:22:42.000000000 +0900
85 @@ -223,6 +223,9 @@
86                      table->sort.found_records*info->ref_length;
87      info->read_record= (table->sort.addon_field ?
88                          rr_unpack_from_buffer : rr_from_pointers);
89 +#ifdef ENABLE_SENNA
90 +    my_thread_var->sen_flags |= 4;
91 +#endif /* ENABLE_SENNA */
92    }
93    else
94    {
95 @@ -387,6 +390,9 @@
96    {
97      if (my_b_read(info->io_cache,info->ref_pos,info->ref_length))
98        return -1;                                       /* End of file */
99 +#ifdef ENABLE_SENNA
100 +    if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) { return 0; }
101 +#endif /* ENABLE_SENNA */
102      if (!(tmp=info->file->rnd_pos(info->record,info->ref_pos)))
103        break;
104      /* The following is extremely unlikely to happen */
105 @@ -440,6 +446,9 @@
106      cache_pos= info->cache_pos;
107      info->cache_pos+= info->ref_length;
108  
109 +#ifdef ENABLE_SENNA
110 +    if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) { return 0; }
111 +#endif /* ENABLE_SENNA */
112      if (!(tmp=info->file->rnd_pos(info->record,cache_pos)))
113        break;
114  
115 diff -Ndur ../mysql-5.1.15-beta.senna/libmysqld/sql_select.cc ./libmysqld/sql_select.cc
116 --- ../mysql-5.1.15-beta.senna/libmysqld/sql_select.cc  2007-01-30 17:34:00.000000000 +0900
117 +++ ./libmysqld/sql_select.cc   2007-02-26 23:24:03.000000000 +0900
118 @@ -1356,6 +1356,10 @@
119    int      tmp_error;
120    DBUG_ENTER("JOIN::exec");
121  
122 +#ifdef ENABLE_SENNA
123 +  my_thread_var->sen_flags |= 32;
124 +#endif /* ENABLE_SENNA */
125 +
126    error= 0;
127    if (procedure)
128    {
129 @@ -1868,6 +1872,10 @@
130    curr_join->fields= curr_fields_list;
131    curr_join->procedure= procedure;
132  
133 +#ifdef ENABLE_SENNA
134 +  my_thread_var->sen_flags &= ~32;
135 +#endif /* ENABLE_SENNA */
136 +
137    if (is_top_level_join() && thd->cursor && tables != const_tables)
138    {
139      /*
140 @@ -2044,7 +2052,10 @@
141        goto err;
142      }
143    }
144 -
145 +#ifdef ENABLE_SENNA
146 +  my_thread_var->sen_flags = select_lex->ftfunc_list->elements ? 1 : 0;
147 +  if (join->select_distinct) { my_thread_var->sen_flags |= 16; }
148 +#endif /* ENABLE_SENNA */
149    if ((err= join->optimize()))
150    {
151      goto err;                                  // 1
152 @@ -3444,7 +3455,11 @@
153    for ( ; field != end ; field++)
154      add_key_part(keyuse,field);
155  
156 -  if (select_lex->ftfunc_list->elements)
157 +  if (select_lex->ftfunc_list->elements
158 +#ifdef ENABLE_SENNA
159 +      && !join_tab->table->force_index
160 +#endif /* ENABLE_SENNA */
161 +      )
162    {
163      add_ft_keys(keyuse,join_tab,cond,normal_tables);
164    }
165 @@ -6047,6 +6062,9 @@
166        table->status=STATUS_NO_RECORD;
167        tab->read_first_record= join_ft_read_first;
168        tab->read_record.read_record= join_ft_read_next;
169 +#ifdef ENABLE_SENNA
170 +      my_thread_var->sen_flags |= 4;
171 +#endif /* ENABLE_SENNA */
172        break;
173      case JT_ALL:
174        /*
175 @@ -10322,6 +10340,20 @@
176    DBUG_RETURN(join->thd->net.report_error ? -1 : rc);
177  }
178  
179 +#ifdef ENABLE_SENNA
180 +static void
181 +decide_read_or_skip(JOIN *join,JOIN_TAB *join_tab,bool needs_record)
182 +{
183 +  if (needs_record || (my_thread_var->sen_flags & 48) ||
184 +      (join_tab->next_select != end_send_group &&
185 +       !join->unit->offset_limit_cnt && 
186 +       join->send_records < join->unit->select_limit_cnt)) {
187 +    my_thread_var->sen_flags |= 8;
188 +  } else {
189 +    my_thread_var->sen_flags &= ~8;
190 +  }
191 +}
192 +#endif /* ENABLE_SENNA */
193  
194  enum_nested_loop_state
195  sub_select_cache(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
196 @@ -10467,6 +10499,9 @@
197  enum_nested_loop_state
198  sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
199  {
200 +#ifdef ENABLE_SENNA
201 +  if (join_tab->next_select == end_update) { my_thread_var->sen_flags &= ~4; }
202 +#endif /* ENABLE_SENNA */
203    join_tab->table->null_row=0;
204    if (end_of_records)
205      return (*join_tab->next_select)(join,join_tab+1,end_of_records);
206 @@ -10475,6 +10510,10 @@
207    enum_nested_loop_state rc;
208    my_bool *report_error= &(join->thd->net.report_error);
209    READ_RECORD *info= &join_tab->read_record;
210 +#ifdef ENABLE_SENNA
211 +  COND *select_cond = join_tab->select_cond;
212 +  bool needs_record = select_cond ? select_cond->needs_record() : false;
213 +#endif /* ENABLE_SENNA */
214  
215    if (join->resume_nested_loop)
216    {
217 @@ -10504,12 +10543,18 @@
218      }
219      join->thd->row_count= 0;
220  
221 +#ifdef ENABLE_SENNA
222 +    decide_read_or_skip(join, join_tab, needs_record);
223 +#endif /* ENABLE_SENNA */
224      error= (*join_tab->read_first_record)(join_tab);
225      rc= evaluate_join_record(join, join_tab, error, report_error);
226    }
227  
228    while (rc == NESTED_LOOP_OK)
229    {
230 +#ifdef ENABLE_SENNA
231 +    decide_read_or_skip(join, join_tab, needs_record);
232 +#endif /* ENABLE_SENNA */
233      error= info->read_record(info);
234      rc= evaluate_join_record(join, join_tab, error, report_error);
235    }
236 @@ -11173,7 +11218,14 @@
237    tab->read_record.record=table->record[0];
238    if (!table->file->inited)
239      table->file->ha_index_init(tab->index, tab->sorted);
240 -  if ((error=tab->table->file->index_first(tab->table->record[0])))
241 +#ifdef ENABLE_SENNA
242 +  if (my_thread_var->sen_flags & 1) { my_thread_var->sen_flags |= 4; }
243 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
244 +    error=tab->table->file->index_first(NULL);
245 +  } else
246 +#endif /* ENABLE_SENNA */
247 +    error=tab->table->file->index_first(tab->table->record[0]);
248 +  if (error)
249    {
250      if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
251        report_error(table, error);
252 @@ -11187,7 +11239,13 @@
253  join_read_next(READ_RECORD *info)
254  {
255    int error;
256 -  if ((error=info->file->index_next(info->record)))
257 +#ifdef ENABLE_SENNA
258 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
259 +    error=info->file->index_next(NULL);
260 +  } else
261 +#endif /* ENABLE_SENNA */
262 +    error=info->file->index_next(info->record);
263 +  if (error)
264      return report_error(info->table, error);
265    return 0;
266  }
267 @@ -11212,7 +11270,14 @@
268    tab->read_record.record=table->record[0];
269    if (!table->file->inited)
270      table->file->ha_index_init(tab->index, 1);
271 -  if ((error= tab->table->file->index_last(tab->table->record[0])))
272 +#ifdef ENABLE_SENNA
273 +  if (my_thread_var->sen_flags & 1) { my_thread_var->sen_flags |= 4; }
274 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
275 +    error=tab->table->file->index_last(NULL);
276 +  } else
277 +#endif /* ENABLE_SENNA */
278 +    error= tab->table->file->index_last(tab->table->record[0]);
279 +  if (error)
280      return report_error(table, error);
281    return 0;
282  }
283 @@ -11222,7 +11287,13 @@
284  join_read_prev(READ_RECORD *info)
285  {
286    int error;
287 -  if ((error= info->file->index_prev(info->record)))
288 +#ifdef ENABLE_SENNA
289 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
290 +    error=info->file->index_prev(NULL);
291 +  } else
292 +#endif /* ENABLE_SENNA */
293 +    error=info->file->index_prev(info->record);
294 +  if (error)
295      return report_error(info->table, error);
296    return 0;
297  }
298 @@ -11236,6 +11307,9 @@
299  
300    if (!table->file->inited)
301      table->file->ha_index_init(tab->ref.key, 1);
302 +#ifdef ENABLE_SENNA
303 +  if (my_thread_var->sen_flags & 1) { my_thread_var->sen_flags |= 4; }
304 +#endif /* ENABLE_SENNA */
305  #if NOT_USED_YET
306    /* as ft-key doesn't use store_key's, see also FT_SELECT::init() */
307    if (cp_buffer_from_ref(tab->join->thd, table, &tab->ref))
308 @@ -12497,6 +12571,12 @@
309    table=  tab->table;
310    select= tab->select;
311  
312 +  #ifdef ENABLE_SENNA
313 +    if (tab->select_cond && tab->select_cond->needs_record()) {
314 +      my_thread_var->sen_flags |= 8;
315 +    }
316 +  #endif /* ENABLE_SENNA */
317 +
318    /*
319      When there is SQL_BIG_RESULT do not sort using index for GROUP BY,
320      and thus force sorting on disk.
321 diff -Ndur ../mysql-5.1.15-beta.senna/sql/filesort.cc ./sql/filesort.cc
322 --- ../mysql-5.1.15-beta.senna/sql/filesort.cc  2007-01-30 17:34:12.000000000 +0900
323 +++ ./sql/filesort.cc   2007-02-26 23:22:42.000000000 +0900
324 @@ -1365,6 +1365,9 @@
325        }
326        if (sortorder->field->maybe_null())
327         length++;                               // Place for NULL marker
328 +#ifdef ENABLE_SENNA
329 +      my_thread_var->sen_flags |= 2;
330 +#endif /* ENABLE_SENNA */
331      }
332      else
333      {
334 diff -Ndur ../mysql-5.1.15-beta.senna/sql/item.h ./sql/item.h
335 --- ../mysql-5.1.15-beta.senna/sql/item.h       2007-01-30 17:34:29.000000000 +0900
336 +++ ./sql/item.h        2007-02-26 23:27:26.000000000 +0900
337 @@ -743,6 +743,10 @@
338    */
339    virtual bool is_null() { return 0; }
340  
341 +  #ifdef ENABLE_SENNA
342 +    virtual bool needs_record() { return true; }
343 +  #endif /* ENABLE_SENNA */
344 +
345    /*
346     Make sure the null_value member has a correct value.
347    */
348 diff -Ndur ../mysql-5.1.15-beta.senna/sql/item_cmpfunc.cc ./sql/item_cmpfunc.cc
349 --- ../mysql-5.1.15-beta.senna/sql/item_cmpfunc.cc      2007-01-30 17:34:26.000000000 +0900
350 +++ ./sql/item_cmpfunc.cc       2007-02-26 23:22:42.000000000 +0900
351 @@ -2402,6 +2402,22 @@
352    return 0;
353  }
354  
355 +#ifdef ENABLE_SENNA
356 +bool 
357 +Item_cond::needs_record()
358 +{
359 +  List_iterator_fast<Item> li(list);
360 +  Item *item;
361 +  while ((item=li++))
362 +  {
363 +    if (item->needs_record())
364 +    {
365 +      return true;
366 +    }
367 +  }
368 +  return false;
369 +}
370 +#endif /* ENABLE_SENNA */
371  
372  /*
373    Perform context analysis of an IN item tree
374 diff -Ndur ../mysql-5.1.15-beta.senna/sql/item_cmpfunc.h ./sql/item_cmpfunc.h
375 --- ../mysql-5.1.15-beta.senna/sql/item_cmpfunc.h       2007-01-30 17:34:37.000000000 +0900
376 +++ ./sql/item_cmpfunc.h        2007-02-26 23:22:42.000000000 +0900
377 @@ -1269,6 +1269,9 @@
378    void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
379    bool fix_fields(THD *, Item **ref);
380  
381 +#ifdef ENABLE_SENNA
382 +  bool needs_record();
383 +#endif /* ENABLE_SENNA */
384    enum Type type() const { return COND_ITEM; }
385    List<Item>* argument_list() { return &list; }
386    table_map used_tables() const;
387 diff -Ndur ../mysql-5.1.15-beta.senna/sql/item_func.cc ./sql/item_func.cc
388 --- ../mysql-5.1.15-beta.senna/sql/item_func.cc 2007-01-30 17:34:37.000000000 +0900
389 +++ ./sql/item_func.cc  2007-02-26 23:22:42.000000000 +0900
390 @@ -4714,7 +4714,11 @@
391    for (keynr=0 ; keynr < table->s->keys ; keynr++)
392    {
393      if ((table->key_info[keynr].flags & HA_FULLTEXT) &&
394 -        (table->keys_in_use_for_query.is_set(keynr)))
395 +        ((table->keys_in_use_for_query.is_set(keynr))
396 +#ifdef ENABLE_SENNA
397 +        || my_thread_var->sen_flags
398 +#endif /* ENABLE_SENNA */
399 +        ))
400      {
401        ft_to_key[fts]=keynr;
402        ft_cnt[fts]=0;
403 diff -Ndur ../mysql-5.1.15-beta.senna/sql/item_func.h ./sql/item_func.h
404 --- ../mysql-5.1.15-beta.senna/sql/item_func.h  2007-01-30 17:34:12.000000000 +0900
405 +++ ./sql/item_func.h   2007-02-26 23:22:42.000000000 +0900
406 @@ -1357,6 +1357,9 @@
407    table_map not_null_tables() const { return 0; }
408    bool fix_fields(THD *thd, Item **ref);
409    bool eq(const Item *, bool binary_cmp) const;
410 +#ifdef ENABLE_SENNA
411 +  bool needs_record() { return false; }
412 +#endif /* ENABLE_SENNA */
413    /* The following should be safe, even if we compare doubles */
414    longlong val_int() { DBUG_ASSERT(fixed == 1); return val_real() != 0.0; }
415    double val_real();
416 diff -Ndur ../mysql-5.1.15-beta.senna/sql/item_sum.cc ./sql/item_sum.cc
417 --- ../mysql-5.1.15-beta.senna/sql/item_sum.cc  2007-01-30 17:34:31.000000000 +0900
418 +++ ./sql/item_sum.cc   2007-02-26 23:22:42.000000000 +0900
419 @@ -2444,6 +2444,9 @@
420      return TRUE;
421  
422    /* Create a table with an unique key over all parameters */
423 +#ifdef ENABLE_SENNA
424 +  my_thread_var->sen_flags |= 16;
425 +#endif /* ENABLE_SENNA */
426    for (uint i=0; i < arg_count ; i++)
427    {
428      Item *item=args[i];
429 diff -Ndur ../mysql-5.1.15-beta.senna/sql/records.cc ./sql/records.cc
430 --- ../mysql-5.1.15-beta.senna/sql/records.cc   2007-01-30 17:34:12.000000000 +0900
431 +++ ./sql/records.cc    2007-02-26 23:22:42.000000000 +0900
432 @@ -223,6 +223,9 @@
433                      table->sort.found_records*info->ref_length;
434      info->read_record= (table->sort.addon_field ?
435                          rr_unpack_from_buffer : rr_from_pointers);
436 +#ifdef ENABLE_SENNA
437 +    my_thread_var->sen_flags |= 4;
438 +#endif /* ENABLE_SENNA */
439    }
440    else
441    {
442 @@ -387,6 +390,9 @@
443    {
444      if (my_b_read(info->io_cache,info->ref_pos,info->ref_length))
445        return -1;                                       /* End of file */
446 +#ifdef ENABLE_SENNA
447 +    if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) { return 0; }
448 +#endif /* ENABLE_SENNA */
449      if (!(tmp=info->file->rnd_pos(info->record,info->ref_pos)))
450        break;
451      /* The following is extremely unlikely to happen */
452 @@ -440,6 +446,9 @@
453      cache_pos= info->cache_pos;
454      info->cache_pos+= info->ref_length;
455  
456 +#ifdef ENABLE_SENNA
457 +    if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) { return 0; }
458 +#endif /* ENABLE_SENNA */
459      if (!(tmp=info->file->rnd_pos(info->record,cache_pos)))
460        break;
461  
462 diff -Ndur ../mysql-5.1.15-beta.senna/sql/sql_select.cc ./sql/sql_select.cc
463 --- ../mysql-5.1.15-beta.senna/sql/sql_select.cc        2007-01-30 17:34:00.000000000 +0900
464 +++ ./sql/sql_select.cc 2007-02-26 23:26:48.000000000 +0900
465 @@ -1356,6 +1356,10 @@
466    int      tmp_error;
467    DBUG_ENTER("JOIN::exec");
468  
469 +#ifdef ENABLE_SENNA
470 +  my_thread_var->sen_flags |= 32;
471 +#endif /* ENABLE_SENNA */
472 +
473    error= 0;
474    if (procedure)
475    {
476 @@ -1868,6 +1872,10 @@
477    curr_join->fields= curr_fields_list;
478    curr_join->procedure= procedure;
479  
480 +#ifdef ENABLE_SENNA
481 +  my_thread_var->sen_flags &= ~32;
482 +#endif /* ENABLE_SENNA */
483 +
484    if (is_top_level_join() && thd->cursor && tables != const_tables)
485    {
486      /*
487 @@ -2044,7 +2052,10 @@
488        goto err;
489      }
490    }
491 -
492 +#ifdef ENABLE_SENNA
493 +  my_thread_var->sen_flags = select_lex->ftfunc_list->elements ? 1 : 0;
494 +  if (join->select_distinct) { my_thread_var->sen_flags |= 16; }
495 +#endif /* ENABLE_SENNA */
496    if ((err= join->optimize()))
497    {
498      goto err;                                  // 1
499 @@ -3444,7 +3455,11 @@
500    for ( ; field != end ; field++)
501      add_key_part(keyuse,field);
502  
503 -  if (select_lex->ftfunc_list->elements)
504 +  if (select_lex->ftfunc_list->elements
505 +#ifdef ENABLE_SENNA
506 +      && !join_tab->table->force_index
507 +#endif /* ENABLE_SENNA */
508 +      )
509    {
510      add_ft_keys(keyuse,join_tab,cond,normal_tables);
511    }
512 @@ -6047,6 +6062,9 @@
513        table->status=STATUS_NO_RECORD;
514        tab->read_first_record= join_ft_read_first;
515        tab->read_record.read_record= join_ft_read_next;
516 +#ifdef ENABLE_SENNA
517 +      my_thread_var->sen_flags |= 4;
518 +#endif /* ENABLE_SENNA */
519        break;
520      case JT_ALL:
521        /*
522 @@ -10322,6 +10340,20 @@
523    DBUG_RETURN(join->thd->net.report_error ? -1 : rc);
524  }
525  
526 +#ifdef ENABLE_SENNA
527 +static void
528 +decide_read_or_skip(JOIN *join,JOIN_TAB *join_tab,bool needs_record)
529 +{
530 +  if (needs_record || (my_thread_var->sen_flags & 48) ||
531 +      (join_tab->next_select != end_send_group &&
532 +       !join->unit->offset_limit_cnt && 
533 +       join->send_records < join->unit->select_limit_cnt)) {
534 +    my_thread_var->sen_flags |= 8;
535 +  } else {
536 +    my_thread_var->sen_flags &= ~8;
537 +  }
538 +}
539 +#endif /* ENABLE_SENNA */
540  
541  enum_nested_loop_state
542  sub_select_cache(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
543 @@ -10467,6 +10499,9 @@
544  enum_nested_loop_state
545  sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
546  {
547 +#ifdef ENABLE_SENNA
548 +  if (join_tab->next_select == end_update) { my_thread_var->sen_flags &= ~4; }
549 +#endif /* ENABLE_SENNA */
550    join_tab->table->null_row=0;
551    if (end_of_records)
552      return (*join_tab->next_select)(join,join_tab+1,end_of_records);
553 @@ -10475,6 +10510,10 @@
554    enum_nested_loop_state rc;
555    my_bool *report_error= &(join->thd->net.report_error);
556    READ_RECORD *info= &join_tab->read_record;
557 +#ifdef ENABLE_SENNA
558 +  COND *select_cond = join_tab->select_cond;
559 +  bool needs_record = select_cond ? select_cond->needs_record() : false;
560 +#endif /* ENABLE_SENNA */
561  
562    if (join->resume_nested_loop)
563    {
564 @@ -10504,12 +10543,18 @@
565      }
566      join->thd->row_count= 0;
567  
568 +#ifdef ENABLE_SENNA
569 +    decide_read_or_skip(join, join_tab, needs_record);
570 +#endif /* ENABLE_SENNA */
571      error= (*join_tab->read_first_record)(join_tab);
572      rc= evaluate_join_record(join, join_tab, error, report_error);
573    }
574  
575    while (rc == NESTED_LOOP_OK)
576    {
577 +#ifdef ENABLE_SENNA
578 +    decide_read_or_skip(join, join_tab, needs_record);
579 +#endif /* ENABLE_SENNA */
580      error= info->read_record(info);
581      rc= evaluate_join_record(join, join_tab, error, report_error);
582    }
583 @@ -11173,7 +11218,14 @@
584    tab->read_record.record=table->record[0];
585    if (!table->file->inited)
586      table->file->ha_index_init(tab->index, tab->sorted);
587 -  if ((error=tab->table->file->index_first(tab->table->record[0])))
588 +#ifdef ENABLE_SENNA
589 +  if (my_thread_var->sen_flags & 1) { my_thread_var->sen_flags |= 4; }
590 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
591 +    error=tab->table->file->index_first(NULL);
592 +  } else
593 +#endif /* ENABLE_SENNA */
594 +    error=tab->table->file->index_first(tab->table->record[0]);
595 +  if (error)
596    {
597      if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
598        report_error(table, error);
599 @@ -11187,7 +11239,13 @@
600  join_read_next(READ_RECORD *info)
601  {
602    int error;
603 -  if ((error=info->file->index_next(info->record)))
604 +#ifdef ENABLE_SENNA
605 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
606 +    error=info->file->index_next(NULL);
607 +  } else
608 +#endif /* ENABLE_SENNA */
609 +    error=info->file->index_next(info->record);
610 +  if (error)
611      return report_error(info->table, error);
612    return 0;
613  }
614 @@ -11212,7 +11270,14 @@
615    tab->read_record.record=table->record[0];
616    if (!table->file->inited)
617      table->file->ha_index_init(tab->index, 1);
618 -  if ((error= tab->table->file->index_last(tab->table->record[0])))
619 +#ifdef ENABLE_SENNA
620 +  if (my_thread_var->sen_flags & 1) { my_thread_var->sen_flags |= 4; }
621 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
622 +    error=tab->table->file->index_last(NULL);
623 +  } else
624 +#endif /* ENABLE_SENNA */
625 +    error= tab->table->file->index_last(tab->table->record[0]);
626 +  if (error)
627      return report_error(table, error);
628    return 0;
629  }
630 @@ -11222,7 +11287,13 @@
631  join_read_prev(READ_RECORD *info)
632  {
633    int error;
634 -  if ((error= info->file->index_prev(info->record)))
635 +#ifdef ENABLE_SENNA
636 +  if ((my_thread_var->sen_flags & (1|4|8)) == (1|4)) {
637 +    error=info->file->index_prev(NULL);
638 +  } else
639 +#endif /* ENABLE_SENNA */
640 +    error=info->file->index_prev(info->record);
641 +  if (error)
642      return report_error(info->table, error);
643    return 0;
644  }
645 @@ -11236,6 +11307,9 @@
646  
647    if (!table->file->inited)
648      table->file->ha_index_init(tab->ref.key, 1);
649 +#ifdef ENABLE_SENNA
650 +  if (my_thread_var->sen_flags & 1) { my_thread_var->sen_flags |= 4; }
651 +#endif /* ENABLE_SENNA */
652  #if NOT_USED_YET
653    /* as ft-key doesn't use store_key's, see also FT_SELECT::init() */
654    if (cp_buffer_from_ref(tab->join->thd, table, &tab->ref))
655 @@ -12497,6 +12571,12 @@
656    table=  tab->table;
657    select= tab->select;
658  
659 +  #ifdef ENABLE_SENNA
660 +    if (tab->select_cond && tab->select_cond->needs_record()) {
661 +      my_thread_var->sen_flags |= 8;
662 +    }
663 +  #endif /* ENABLE_SENNA */
664 +
665    /*
666      When there is SQL_BIG_RESULT do not sort using index for GROUP BY,
667      and thus force sorting on disk.
668 diff -Ndur ../mysql-5.1.15-beta.senna/storage/myisam/ft_boolean_search.c ./storage/myisam/ft_boolean_search.c
669 --- ../mysql-5.1.15-beta.senna/storage/myisam/ft_boolean_search.c       2007-02-26 21:07:21.000000000 +0900
670 +++ ./storage/myisam/ft_boolean_search.c        2007-02-26 23:22:42.000000000 +0900
671 @@ -794,6 +794,7 @@
672      while (ftb->sir && sen_records_next(ftb->sir, &pos, sizeof(my_off_t), NULL)) {
673        info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
674        info->lastpos=pos;
675 +      if (!(my_thread_var->sen_flags & (8|2))) { return 0; }
676        if (!(*info->read_record)(info,info->lastpos,record)) {
677          info->update|= HA_STATE_AKTIV;          /* Record is read */
678          return 0;
679 diff -Ndur ../mysql-5.1.15-beta.senna/storage/myisam/ft_nlq_search.c ./storage/myisam/ft_nlq_search.c
680 --- ../mysql-5.1.15-beta.senna/storage/myisam/ft_nlq_search.c   2007-02-26 21:07:21.000000000 +0900
681 +++ ./storage/myisam/ft_nlq_search.c    2007-02-26 23:22:42.000000000 +0900
682 @@ -334,6 +334,7 @@
683      while (sen_records_next(handler->sir, &pos, sizeof(my_off_t), NULL))
684      {
685        info->lastpos=pos;
686 +      if (!(my_thread_var->sen_flags & (8|2))) { return 0; }
687        if (!(*info->read_record)(info,info->lastpos,record))
688        {
689         info->update|= HA_STATE_AKTIV;          /* Record is read */