~kentokushiba/spiderformysql/spider-2.0-src

« back to all changes in this revision

Viewing changes to ha_spider.cc

  • Committer: Kentoku SHIBA
  • Date: 2011-05-12 15:25:47 UTC
  • Revision ID: kentokushiba@gmail.com-20110512152547-6hb2cvwnbg7v6ax3
2.25

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
  pt_clone_source_handler = NULL;
78
78
  pt_clone_last_searcher = NULL;
79
79
  ft_handler = NULL;
80
 
  ft_init_key = NULL;
 
80
  ft_first = NULL;
 
81
  ft_current = NULL;
 
82
  ft_count = 0;
 
83
  ft_init_without_index_init = FALSE;
81
84
  sql_kinds = 0;
82
85
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
83
86
  do_direct_update = FALSE;
93
96
  result_list.tmp_sqls = NULL;
94
97
  result_list.tmp_tables_created = FALSE;
95
98
  result_list.bgs_working = FALSE;
 
99
  result_list.direct_order_limit = FALSE;
96
100
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
97
101
  result_list.hs_has_result = FALSE;
98
102
#ifndef HANDLERSOCKET_MYSQL_UTIL
132
136
  pt_clone_source_handler = NULL;
133
137
  pt_clone_last_searcher = NULL;
134
138
  ft_handler = NULL;
135
 
  ft_init_key = NULL;
 
139
  ft_first = NULL;
 
140
  ft_current = NULL;
 
141
  ft_count = 0;
 
142
  ft_init_without_index_init = FALSE;
136
143
  sql_kinds = 0;
137
144
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
138
145
  do_direct_update = FALSE;
148
155
  result_list.tmp_sqls = NULL;
149
156
  result_list.tmp_tables_created = FALSE;
150
157
  result_list.bgs_working = FALSE;
 
158
  result_list.direct_order_limit = FALSE;
151
159
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
152
160
  result_list.hs_has_result = FALSE;
153
161
#ifndef HANDLERSOCKET_MYSQL_UTIL
401
409
  }
402
410
 
403
411
#ifdef WITH_PARTITION_STORAGE_ENGINE
404
 
  if (may_be_clone)
 
412
  if (may_be_clone && thd_sql_command(thd) != SQLCOM_ALTER_TABLE)
405
413
    is_clone = TRUE;
406
414
#endif
407
415
  if (is_clone)
532
540
      conns[roop_count] = NULL;
533
541
  }
534
542
 
 
543
  if (ft_first)
 
544
  {
 
545
    st_spider_ft_info *tmp_ft_info;
 
546
    do {
 
547
      tmp_ft_info = ft_first->next;
 
548
      my_free(ft_first, MYF(0));
 
549
      ft_first = tmp_ft_info;
 
550
    } while (ft_first);
 
551
  }
 
552
 
535
553
  spider_db_free_result(this, TRUE);
536
554
  if (conn_keys)
537
555
  {
1333
1351
  }
1334
1352
#endif
1335
1353
  ft_handler = NULL;
1336
 
  ft_init_key = NULL;
 
1354
  ft_current = NULL;
 
1355
  ft_count = 0;
 
1356
  ft_init_without_index_init = FALSE;
1337
1357
  sql_kinds = 0;
1338
1358
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1339
1359
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
1341
1361
#endif
1342
1362
#endif
1343
1363
  result_list.have_sql_kind_backup = FALSE;
 
1364
  result_list.direct_order_limit = FALSE;
 
1365
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
 
1366
#ifndef HANDLERSOCKET_MYSQL_UTIL
 
1367
#else
 
1368
  if (result_list.hs_da_init)
 
1369
    spider_db_free_str_dynamic(&result_list.hs_strs);
 
1370
#endif
 
1371
#endif
1344
1372
  DBUG_RETURN(error_num);
1345
1373
}
1346
1374
 
1521
1549
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1522
1550
  result_list.hs_sql.length(0);
1523
1551
#endif
 
1552
  result_list.check_direct_order_limit = FALSE;
1524
1553
  DBUG_RETURN(0);
1525
1554
}
1526
1555
 
1561
1590
  spider_db_free_one_result_for_start_next(this);
1562
1591
  lock_mode = spider_conn_lock_mode(this);
1563
1592
  spider_set_result_list_param(this);
 
1593
  check_direct_order_limit();
1564
1594
  start_key.key = key;
1565
1595
  start_key.keypart_map = keypart_map;
1566
1596
  start_key.flag = find_flag;
1847
1877
  )
1848
1878
    DBUG_RETURN(error_num);
1849
1879
 
 
1880
  check_direct_order_limit();
1850
1881
  start_key.key = key;
1851
1882
  start_key.keypart_map = keypart_map;
1852
1883
  start_key.flag = HA_READ_KEY_EXACT;
2155
2186
    if ((error_num = spider_db_free_result(this, FALSE)))
2156
2187
      DBUG_RETURN(error_num);
2157
2188
 
 
2189
    check_direct_order_limit();
2158
2190
#ifndef WITHOUT_SPIDER_BG_SEARCH
2159
2191
    if ((error_num = spider_set_conn_bg_param(this)))
2160
2192
      DBUG_RETURN(error_num);
2428
2460
    if ((error_num = spider_db_free_result(this, FALSE)))
2429
2461
      DBUG_RETURN(error_num);
2430
2462
 
 
2463
    check_direct_order_limit();
2431
2464
#ifndef WITHOUT_SPIDER_BG_SEARCH
2432
2465
    if ((error_num = spider_set_conn_bg_param(this)))
2433
2466
      DBUG_RETURN(error_num);
2713
2746
    pt_clone_source_handler->pt_clone_last_searcher = this;
2714
2747
  }
2715
2748
  spider_db_free_one_result_for_start_next(this);
 
2749
  check_direct_order_limit();
2716
2750
  result_list.sql.length(0);
2717
2751
  result_list.ha_sql.length(0);
2718
2752
#ifndef WITHOUT_SPIDER_BG_SEARCH
3101
3135
#endif
3102
3136
 
3103
3137
  spider_db_free_one_result_for_start_next(this);
 
3138
  check_direct_order_limit();
3104
3139
#ifndef WITHOUT_SPIDER_BG_SEARCH
3105
3140
  if ((error_num = spider_set_conn_bg_param(this)))
3106
3141
    DBUG_RETURN(error_num);
5488
5523
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5489
5524
      result_list.hs_sql.length(0);
5490
5525
#endif
 
5526
      result_list.check_direct_order_limit = FALSE;
5491
5527
    }
5492
5528
  }
5493
5529
  DBUG_RETURN(0);
5518
5554
      DBUG_RETURN(HA_ERR_WRONG_COMMAND);
5519
5555
#endif
5520
5556
 
 
5557
    check_direct_order_limit();
5521
5558
#ifdef WITH_PARTITION_STORAGE_ENGINE
5522
5559
    check_select_column(TRUE);
5523
5560
#endif
5536
5573
      DBUG_RETURN(HA_ERR_OUT_OF_MEM);
5537
5574
 
5538
5575
    result_list.order_pos = result_list.sql.length();
 
5576
    if (
 
5577
      result_list.direct_order_limit &&
 
5578
      (error_num = spider_db_append_key_order(this, FALSE))
 
5579
    )
 
5580
      DBUG_RETURN(error_num);
5539
5581
    result_list.limit_pos = result_list.order_pos;
5540
5582
    result_list.ha_limit_pos = result_list.ha_sql.length();
5541
5583
    result_list.desc_flg = FALSE;
5794
5836
  DBUG_RETURN(spider_db_seek_tmp(buf, tmp_pos, this, table));
5795
5837
}
5796
5838
 
 
5839
float spider_ft_find_relevance(
 
5840
  FT_INFO *handler,
 
5841
  uchar *record,
 
5842
  uint length
 
5843
) {
 
5844
  DBUG_ENTER("spider_ft_find_relevance");
 
5845
  st_spider_ft_info *info = (st_spider_ft_info*) handler;
 
5846
  DBUG_PRINT("info",("spider info=%p", info));
 
5847
  DBUG_PRINT("info",("spider score=%f", info->score));
 
5848
  DBUG_RETURN(info->score);
 
5849
}
 
5850
 
 
5851
float spider_ft_get_relevance(
 
5852
  FT_INFO *handler
 
5853
) {
 
5854
  DBUG_ENTER("spider_ft_get_relevance");
 
5855
  st_spider_ft_info *info = (st_spider_ft_info*) handler;
 
5856
  DBUG_PRINT("info",("spider info=%p", info));
 
5857
  DBUG_PRINT("info",("spider score=%f", info->score));
 
5858
  DBUG_RETURN(info->score);
 
5859
}
 
5860
 
 
5861
void spider_ft_close_search(
 
5862
  FT_INFO *handler
 
5863
) {
 
5864
  DBUG_ENTER("spider_ft_close_search");
 
5865
  DBUG_VOID_RETURN;
 
5866
}
 
5867
 
 
5868
_ft_vft spider_ft_vft = {
 
5869
  NULL, // spider_ft_read_next
 
5870
  spider_ft_find_relevance,
 
5871
  spider_ft_close_search,
 
5872
  spider_ft_get_relevance,
 
5873
  NULL // spider_ft_reinit_search
 
5874
};
 
5875
 
5797
5876
int ha_spider::ft_init()
5798
5877
{
5799
 
  int roop_count;
 
5878
  int roop_count, error_num;
5800
5879
  DBUG_ENTER("ha_spider::ft_init");
5801
5880
  DBUG_PRINT("info",("spider this=%x", this));
 
5881
  if (store_error_num)
 
5882
    DBUG_RETURN(store_error_num);
 
5883
  if (active_index == MAX_KEY && inited == NONE)
 
5884
  {
 
5885
    st_spider_ft_info  *ft_info = ft_first;
 
5886
    ft_init_without_index_init = TRUE;
 
5887
    ft_init_idx = MAX_KEY;
 
5888
    while (TRUE)
 
5889
    {
 
5890
      if (ft_info->used_in_where)
 
5891
      {
 
5892
        ft_init_idx = ft_info->inx;
 
5893
        if ((error_num = index_init(ft_init_idx, FALSE)))
 
5894
          DBUG_RETURN(error_num);
 
5895
        active_index = MAX_KEY;
 
5896
        break;
 
5897
      }
 
5898
      if (ft_info == ft_current)
 
5899
        break;
 
5900
      ft_info = ft_info->next;
 
5901
    }
 
5902
    if (ft_init_idx == MAX_KEY)
 
5903
    {
 
5904
      if ((error_num = rnd_init(TRUE)))
 
5905
        DBUG_RETURN(error_num);
 
5906
    }
 
5907
  } else {
 
5908
    ft_init_idx = active_index;
 
5909
    ft_init_without_index_init = FALSE;
 
5910
  }
 
5911
 
5802
5912
  ft_init_and_first = TRUE;
5803
5913
 
5804
5914
  for (roop_count = 0; roop_count < share->link_count; roop_count++)
5812
5922
  DBUG_ENTER("ha_spider::ft_end");
5813
5923
  DBUG_PRINT("info",("spider this=%x", this));
5814
5924
  ft_handler = NULL;
5815
 
  ft_init_key = NULL;
 
5925
  ft_current = NULL;
 
5926
  ft_count = 0;
 
5927
  if (ft_init_without_index_init)
 
5928
  {
 
5929
    if (ft_init_idx == MAX_KEY)
 
5930
      store_error_num = rnd_end();
 
5931
    else
 
5932
      store_error_num = index_end();
 
5933
  }
 
5934
  ft_init_without_index_init = FALSE;
5816
5935
  DBUG_VOID_RETURN;
5817
5936
}
5818
5937
 
5821
5940
  uint inx,
5822
5941
  String *key
5823
5942
) {
 
5943
  st_spider_ft_info *tmp_ft_info;
5824
5944
  DBUG_ENTER("ha_spider::ft_init_ext");
5825
5945
  DBUG_PRINT("info",("spider this=%x", this));
5826
 
  DBUG_PRINT("info",("vp flags=%u", flags));
5827
 
  DBUG_PRINT("info",("vp inx=%u", inx));
5828
 
  DBUG_PRINT("info",("vp key=%s", key->ptr()));
5829
 
  ft_init_flags = flags;
5830
 
  ft_init_key = key;
5831
 
  DBUG_RETURN(NULL);
 
5946
  DBUG_PRINT("info",("spider flags=%u", flags));
 
5947
  DBUG_PRINT("info",("spider inx=%u", inx));
 
5948
  DBUG_PRINT("info",("spider key=%s", key->ptr()));
 
5949
  tmp_ft_info = ft_current;
 
5950
  if (ft_current)
 
5951
    ft_current = ft_current->next;
 
5952
  else
 
5953
    ft_current = ft_first;
 
5954
 
 
5955
  if (!ft_current)
 
5956
  {
 
5957
    if (!(ft_current = (st_spider_ft_info *)
 
5958
      my_malloc(sizeof(st_spider_ft_info), MYF(MY_WME | MY_ZEROFILL))))
 
5959
    {
 
5960
      store_error_num = HA_ERR_OUT_OF_MEM;
 
5961
      DBUG_RETURN(NULL);
 
5962
    }
 
5963
    if (tmp_ft_info)
 
5964
      tmp_ft_info->next = ft_current;
 
5965
    else
 
5966
      ft_first = ft_current;
 
5967
  }
 
5968
 
 
5969
  ft_current->please = &spider_ft_vft;
 
5970
  ft_current->file = this;
 
5971
  ft_current->used_in_where = (flags & FT_SORTED);
 
5972
  ft_current->target = ft_count;
 
5973
  ft_current->flags = flags;
 
5974
  ft_current->inx = inx;
 
5975
  ft_current->key = key;
 
5976
 
 
5977
  ft_count++;
 
5978
  DBUG_RETURN((FT_INFO *) ft_current);
5832
5979
}
5833
5980
 
5834
5981
int ha_spider::ft_read(
5843
5990
 
5844
5991
    ft_init_and_first = FALSE;
5845
5992
    spider_db_free_one_result_for_start_next(this);
 
5993
    check_direct_order_limit();
5846
5994
#ifndef WITHOUT_SPIDER_BG_SEARCH
5847
5995
    if ((error_num = spider_set_conn_bg_param(this)))
5848
5996
      DBUG_RETURN(error_num);
5863
6011
    )
5864
6012
      DBUG_RETURN(error_num);
5865
6013
    if (
 
6014
      ft_init_idx < MAX_KEY &&
5866
6015
      share->key_hint &&
5867
6016
      (error_num = spider_db_append_hint_after_table(this,
5868
 
        &result_list.sql, &share->key_hint[active_index]))
 
6017
        &result_list.sql, &share->key_hint[ft_init_idx]))
5869
6018
    )
5870
6019
      DBUG_RETURN(HA_ERR_OUT_OF_MEM);
5871
6020
    result_list.where_pos = result_list.sql.length();
5872
6021
    result_list.desc_flg = FALSE;
5873
6022
    result_list.sorted = TRUE;
5874
 
    result_list.key_info = &table->key_info[active_index];
 
6023
    if (ft_init_idx == MAX_KEY)
 
6024
      result_list.key_info = NULL;
 
6025
    else
 
6026
      result_list.key_info = &table->key_info[ft_init_idx];
5875
6027
    result_list.key_order = 0;
5876
6028
    result_list.limit_num =
5877
6029
      result_list.internal_limit >= result_list.split_read ?
5878
6030
      result_list.split_read : result_list.internal_limit;
5879
6031
    if (
5880
 
      (error_num = spider_db_append_match_where(this))
 
6032
      (error_num = spider_db_append_match_where(this)) ||
 
6033
      (
 
6034
        result_list.direct_order_limit &&
 
6035
        (error_num = spider_db_append_key_order(this, FALSE))
 
6036
      )
5881
6037
    )
5882
6038
      DBUG_RETURN(error_num);
5883
6039
    result_list.limit_pos = result_list.sql.length();
6886
7042
    if (pk_update && spider_check_hs_pk_update(this, &ranges->start_key))
6887
7043
      DBUG_RETURN(HA_ERR_WRONG_COMMAND);
6888
7044
#endif
 
7045
    trx->direct_update_count++;
6889
7046
    DBUG_RETURN(0);
6890
7047
  }
6891
7048
  DBUG_RETURN(HA_ERR_WRONG_COMMAND);
6955
7112
    sql_command == SQLCOM_HS_DELETE &&
6956
7113
#endif
6957
7114
    do_direct_update
6958
 
  )
 
7115
  ) {
 
7116
    trx->direct_delete_count++;
6959
7117
    DBUG_RETURN(0);
 
7118
  }
6960
7119
  DBUG_RETURN(HA_ERR_WRONG_COMMAND);
6961
7120
}
6962
7121
 
7574
7733
  const COND *cond
7575
7734
) {
7576
7735
  DBUG_ENTER("ha_spider::cond_push");
 
7736
  cond_check = FALSE;
7577
7737
  if (cond)
7578
7738
  {
7579
7739
    SPIDER_CONDITION *tmp_cond;
7600
7760
  DBUG_VOID_RETURN;
7601
7761
}
7602
7762
 
7603
 
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
7604
7763
int ha_spider::info_push(
7605
7764
  uint info_type,
7606
7765
  void *info
7607
7766
) {
7608
7767
  DBUG_ENTER("ha_spider::info_push");
 
7768
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
7609
7769
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7610
7770
  if (info_type == INFO_KIND_HS_RET_FIELDS)
7611
7771
  {
7625
7785
    }
7626
7786
  }
7627
7787
#endif
 
7788
#endif
7628
7789
  DBUG_RETURN(0);
7629
7790
}
7630
 
#endif
7631
7791
 
7632
7792
TABLE *ha_spider::get_table()
7633
7793
{
7877
8037
  DBUG_RETURN(0);
7878
8038
}
7879
8039
 
 
8040
void ha_spider::check_direct_order_limit()
 
8041
{
 
8042
  int roop_count;
 
8043
  DBUG_ENTER("ha_spider::check_direct_order_limit");
 
8044
  DBUG_PRINT("info",("spider this=%x", this));
 
8045
  if (!result_list.check_direct_order_limit)
 
8046
  {
 
8047
    if (spider_check_direct_order_limit(this))
 
8048
    {
 
8049
      result_list.direct_order_limit = TRUE;
 
8050
      sql_kinds = SPIDER_SQL_KIND_SQL;
 
8051
      for (roop_count = 0; roop_count < share->link_count; roop_count++)
 
8052
        sql_kind[roop_count] = SPIDER_SQL_KIND_SQL;
 
8053
    } else
 
8054
      result_list.direct_order_limit = FALSE;
 
8055
    result_list.check_direct_order_limit = TRUE;
 
8056
  }
 
8057
  DBUG_VOID_RETURN;
 
8058
}
 
8059
 
7880
8060
int ha_spider::drop_tmp_tables()
7881
8061
{
7882
8062
  int error_num = 0, tmp_error_num;