~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/opt_range.cc

Standardized TRUE/FALSE, removed/replaced DBUG symbols, and removed custom dbug funcs for optimizer (these should go away anyway...)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9790
9790
  return;
9791
9791
}
9792
9792
 
9793
 
 
9794
 
/*****************************************************************************
9795
 
** Print a quick range for debugging
9796
 
** TODO:
9797
 
** This should be changed to use a String to store each row instead
9798
 
** of locking the DEBUG stream !
9799
 
*****************************************************************************/
9800
 
 
9801
 
static void
9802
 
print_key(KEY_PART *key_part, const uchar *key, uint used_length)
9803
 
{
9804
 
  char buff[1024];
9805
 
  const uchar *key_end= key+used_length;
9806
 
  String tmp(buff,sizeof(buff),&my_charset_bin);
9807
 
  uint store_length;
9808
 
  TABLE *table= key_part->field->table;
9809
 
  my_bitmap_map *old_write_set, *old_read_set;
9810
 
  old_write_set= dbug_tmp_use_all_columns(table, table->write_set);
9811
 
  old_read_set=  dbug_tmp_use_all_columns(table, table->read_set);
9812
 
 
9813
 
  for (; key < key_end; key+=store_length, key_part++)
9814
 
  {
9815
 
    Field *field=      key_part->field;
9816
 
    store_length= key_part->store_length;
9817
 
 
9818
 
    if (field->real_maybe_null())
9819
 
    {
9820
 
      if (*key)
9821
 
      {
9822
 
        fwrite("NULL",sizeof(char),4,DBUG_FILE);
9823
 
        continue;
9824
 
      }
9825
 
      key++;                                    // Skip null byte
9826
 
      store_length--;
9827
 
    }
9828
 
    field->set_key_image(key, key_part->length);
9829
 
    field->val_str(&tmp);
9830
 
    fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);
9831
 
    if (key+store_length < key_end)
9832
 
      fputc('/',DBUG_FILE);
9833
 
  }
9834
 
  dbug_tmp_restore_column_map(table->write_set, old_write_set);
9835
 
  dbug_tmp_restore_column_map(table->read_set, old_read_set);
9836
 
}
9837
 
 
9838
 
 
9839
 
static void print_quick(QUICK_SELECT_I *quick, const key_map *needed_reg)
9840
 
{
9841
 
  char buf[MAX_KEY/8+1];
9842
 
  TABLE *table;
9843
 
  my_bitmap_map *old_read_map, *old_write_map;
9844
 
  if (!quick)
9845
 
    return;
9846
 
  DBUG_LOCK_FILE;
9847
 
 
9848
 
  table= quick->head;
9849
 
  old_read_map=  dbug_tmp_use_all_columns(table, table->read_set);
9850
 
  old_write_map= dbug_tmp_use_all_columns(table, table->write_set);
9851
 
  quick->dbug_dump(0, true);
9852
 
  dbug_tmp_restore_column_map(table->read_set, old_read_map);
9853
 
  dbug_tmp_restore_column_map(table->write_set, old_write_map);
9854
 
 
9855
 
  fprintf(DBUG_FILE,"other_keys: 0x%s:\n", needed_reg->print(buf));
9856
 
 
9857
 
  DBUG_UNLOCK_FILE;
9858
 
  return;
9859
 
}
9860
 
 
9861
 
 
9862
 
void QUICK_RANGE_SELECT::dbug_dump(int indent, bool verbose)
9863
 
{
9864
 
  /* purecov: begin inspected */
9865
 
  fprintf(DBUG_FILE, "%*squick range select, key %s, length: %d\n",
9866
 
          indent, "", head->key_info[index].name, max_used_key_length);
9867
 
 
9868
 
  if (verbose)
9869
 
  {
9870
 
    QUICK_RANGE *range;
9871
 
    QUICK_RANGE **pr= (QUICK_RANGE**)ranges.buffer;
9872
 
    QUICK_RANGE **end_range= pr + ranges.elements;
9873
 
    for (; pr != end_range; ++pr)
9874
 
    {
9875
 
      fprintf(DBUG_FILE, "%*s", indent + 2, "");
9876
 
      range= *pr;
9877
 
      if (!(range->flag & NO_MIN_RANGE))
9878
 
      {
9879
 
        print_key(key_parts, range->min_key, range->min_length);
9880
 
        if (range->flag & NEAR_MIN)
9881
 
          fputs(" < ",DBUG_FILE);
9882
 
        else
9883
 
          fputs(" <= ",DBUG_FILE);
9884
 
      }
9885
 
      fputs("X",DBUG_FILE);
9886
 
 
9887
 
      if (!(range->flag & NO_MAX_RANGE))
9888
 
      {
9889
 
        if (range->flag & NEAR_MAX)
9890
 
          fputs(" < ",DBUG_FILE);
9891
 
        else
9892
 
          fputs(" <= ",DBUG_FILE);
9893
 
        print_key(key_parts, range->max_key, range->max_length);
9894
 
      }
9895
 
      fputs("\n",DBUG_FILE);
9896
 
    }
9897
 
  }
9898
 
  /* purecov: end */    
9899
 
}
9900
 
 
9901
 
void QUICK_INDEX_MERGE_SELECT::dbug_dump(int indent, bool verbose)
9902
 
{
9903
 
  List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
9904
 
  QUICK_RANGE_SELECT *quick;
9905
 
  fprintf(DBUG_FILE, "%*squick index_merge select\n", indent, "");
9906
 
  fprintf(DBUG_FILE, "%*smerged scans {\n", indent, "");
9907
 
  while ((quick= it++))
9908
 
    quick->dbug_dump(indent+2, verbose);
9909
 
  if (pk_quick_select)
9910
 
  {
9911
 
    fprintf(DBUG_FILE, "%*sclustered PK quick:\n", indent, "");
9912
 
    pk_quick_select->dbug_dump(indent+2, verbose);
9913
 
  }
9914
 
  fprintf(DBUG_FILE, "%*s}\n", indent, "");
9915
 
}
9916
 
 
9917
 
void QUICK_ROR_INTERSECT_SELECT::dbug_dump(int indent, bool verbose)
9918
 
{
9919
 
  List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
9920
 
  QUICK_RANGE_SELECT *quick;
9921
 
  fprintf(DBUG_FILE, "%*squick ROR-intersect select, %scovering\n",
9922
 
          indent, "", need_to_fetch_row? "":"non-");
9923
 
  fprintf(DBUG_FILE, "%*smerged scans {\n", indent, "");
9924
 
  while ((quick= it++))
9925
 
    quick->dbug_dump(indent+2, verbose);
9926
 
  if (cpk_quick)
9927
 
  {
9928
 
    fprintf(DBUG_FILE, "%*sclustered PK quick:\n", indent, "");
9929
 
    cpk_quick->dbug_dump(indent+2, verbose);
9930
 
  }
9931
 
  fprintf(DBUG_FILE, "%*s}\n", indent, "");
9932
 
}
9933
 
 
9934
 
void QUICK_ROR_UNION_SELECT::dbug_dump(int indent, bool verbose)
9935
 
{
9936
 
  List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
9937
 
  QUICK_SELECT_I *quick;
9938
 
  fprintf(DBUG_FILE, "%*squick ROR-union select\n", indent, "");
9939
 
  fprintf(DBUG_FILE, "%*smerged scans {\n", indent, "");
9940
 
  while ((quick= it++))
9941
 
    quick->dbug_dump(indent+2, verbose);
9942
 
  fprintf(DBUG_FILE, "%*s}\n", indent, "");
9943
 
}
9944
 
 
9945
 
 
9946
 
/*
9947
 
  Print quick select information to DBUG_FILE.
9948
 
 
9949
 
  SYNOPSIS
9950
 
    QUICK_GROUP_MIN_MAX_SELECT::dbug_dump()
9951
 
    indent  Indentation offset
9952
 
    verbose If true show more detailed output.
9953
 
 
9954
 
  DESCRIPTION
9955
 
    Print the contents of this quick select to DBUG_FILE. The method also
9956
 
    calls dbug_dump() for the used quick select if any.
9957
 
 
9958
 
  IMPLEMENTATION
9959
 
    Caller is responsible for locking DBUG_FILE before this call and unlocking
9960
 
    it afterwards.
9961
 
 
9962
 
  RETURN
9963
 
    None
9964
 
*/
9965
 
 
9966
 
void QUICK_GROUP_MIN_MAX_SELECT::dbug_dump(int indent, bool verbose)
9967
 
{
9968
 
  fprintf(DBUG_FILE,
9969
 
          "%*squick_group_min_max_select: index %s (%d), length: %d\n",
9970
 
          indent, "", index_info->name, index, max_used_key_length);
9971
 
  if (key_infix_len > 0)
9972
 
  {
9973
 
    fprintf(DBUG_FILE, "%*susing key_infix with length %d:\n",
9974
 
            indent, "", key_infix_len);
9975
 
  }
9976
 
  if (quick_prefix_select)
9977
 
  {
9978
 
    fprintf(DBUG_FILE, "%*susing quick_range_select:\n", indent, "");
9979
 
    quick_prefix_select->dbug_dump(indent + 2, verbose);
9980
 
  }
9981
 
  if (min_max_ranges.elements > 0)
9982
 
  {
9983
 
    fprintf(DBUG_FILE, "%*susing %d quick_ranges for MIN/MAX:\n",
9984
 
            indent, "", min_max_ranges.elements);
9985
 
  }
9986
 
}
9987
 
 
9988
9793
/*****************************************************************************
9989
9794
** Instantiate templates 
9990
9795
*****************************************************************************/