List:Internals« Previous MessageNext Message »
From:Patrick Galbraith Date:January 14 2005 3:22am
Subject:bk commit into 5.0 tree (patg:1.1776)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of patg. When patg does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet
  1.1776 05/01/13 18:21:54 patg@stripped +2 -0
  progress in fixing multi-key, two-byte prefix keys.

  sql/ha_federated.h
    1.3 05/01/13 18:21:36 patg@stripped +1 -0
    added method declaration of create_where_from_key

  sql/ha_federated.cc
    1.7 05/01/13 18:21:36 patg@stripped +139 -13
    added code to handle multi-keys (per monty). This code still fails to compile because
sql_analyse.cc's method, append_escaped only accepts two string pointers. I don't know if
append_escaped will be overloaded to accept string pointer, byte/char pointer, and length,
as is being passed in this example. Need to talk to devs/monty about this.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	patg
# Host:	patrick-galbraiths-computer.local
# Root:	/Users/patg/mysql-5.0

--- 1.6/sql/ha_federated.cc	Mon Jan 10 09:18:14 2005
+++ 1.7/sql/ha_federated.cc	Thu Jan 13 18:21:36 2005
@@ -586,6 +586,103 @@
   DBUG_RETURN(0);
 }
 
+bool ha_federated::create_where_from_key(
+  String *to,
+  KEY *key_info,
+  const byte *key, 
+  uint key_length
+  )
+{
+  uint second_loop= 0;
+  KEY_PART_INFO *key_part;
+
+  DBUG_ENTER("ha_federated::create_where_from_key");
+  for (key_part= key_info->key_part ; (int) key_length > 0 ; key_part++)
+  {
+    Field *field= key_part->field;
+    uint length= key_part->length;
+
+    if (second_loop++ && to->append(" AND ",5))
+      DBUG_RETURN(1);
+    if (to->append('`') || to->append(field->field_name) ||
+        to->append("` ",2))
+      DBUG_RETURN(1);                                 // Out of memory
+
+    if (key_part->null_bit)
+    {
+      if (*key++)
+      {
+        if (to->append("IS NULL",7))
+          DBUG_RETURN(1);
+        key_length-= key_part->store_length;
+        key+= key_part->store_length-1;
+        continue;
+      }
+      key_length--;
+    }
+    if (to->append('='))
+      DBUG_RETURN(1);
+    if (key_part->type == HA_KEYTYPE_BIT)
+    {
+      /* This is can be threated as a hex string */
+      Field_bit *field= (Field_bit *) (key_part->field);
+      char buff[64+2], *ptr;
+      byte *end= key + length;
+
+      buff[0]='0';
+      buff[1]='x';
+      for (ptr= buff+2 ; key < end ; key++)
+      {
+        uint tmp= (uint) (uchar) *key;
+        *ptr++=_dig_vec_upper[tmp >> 4];
+        *ptr++=_dig_vec_upper[tmp & 15];
+      }
+      if (to->append(buff, (uint) (ptr-buff)))
+        DBUG_RETURN(1);
+      key_length-= length;
+      continue;
+    }
+    if (key_part->key_part_flag & HA_BLOB_PART)
+    {
+      uint blob_length= uint2korr(key);
+      key+= HA_KEY_BLOB_LENGTH;
+      key_length-= HA_KEY_BLOB_LENGTH;
+      if (append_escaped(to, key, blob_length))
+        DBUG_RETURN(1);
+      length= key_part->length;
+    }
+    else if (key_part->key_part_flag & HA_VAR_LENGTH_PART)
+    {
+      key_length-= HA_KEY_BLOB_LENGTH;
+      length= key_part->length;
+      key+= HA_KEY_BLOB_LENGTH;
+      if (append_escaped(to, key, length))
+        DBUG_RETURN(1);
+    }
+    else
+    {
+      //bool need_quotes= field->needs_quotes();
+      bool needs_quotes= type_quote(field->type());
+      char buff[MAX_FIELD_WIDTH];
+      String str(buff, sizeof(buff), field->charset()), *res;
+
+      if (needs_quotes && to->append('='))
+        DBUG_RETURN(1);
+      res= field->val_str(&str, (char *)(key));
+      if (field->result_type() == STRING_RESULT)
+      {
+        if (append_escaped(to, res->ptr(), res->length()))
+          DBUG_RETURN(1);
+      }
+      else if (to->append(res->ptr(), res->length()))
+        DBUG_RETURN(1);
+      if (needs_quotes && to->append('='))
+        DBUG_RETURN(1);
+    }
+    key+= length;
+    key_length-= length;
+  }
+}
 /* 
   SYNOPSIS
     quote_data()
@@ -612,13 +709,13 @@
 
   int quote_flag;
   DBUG_ENTER("ha_federated::quote_data");
+  DBUG_PRINT("ha_federated::quote_data",
+    ("unescaped %s", unquoted_string->c_ptr_quick()));
   // this is the same call that mysql_real_escape_string() calls
-  escape_string_for_mysql(&my_charset_bin, (char *)escaped_string, 
+  escape_string_for_mysql(&my_charset_bin, (char *)escaped_string,
     unquoted_string->c_ptr_quick(), unquoted_string->length());
 
-  DBUG_PRINT("ha_federated::quote_data",
-    ("escape_string_for_mysql unescaped %s escaped %s",
-     unquoted_string->c_ptr_quick(), escaped_string));
+  DBUG_PRINT("ha_federated::quote_data",("escaped %s",escaped_string));
 
   if (field->is_null())
   {
@@ -630,6 +727,9 @@
 
   quote_flag= type_quote(field->type());
 
+  DBUG_PRINT("ha_federated::quote_data",
+      ("quote flag %d type %d", quote_flag, field->type()));
+
   if (quote_flag == 0)
   {
     DBUG_PRINT("ha_federated::quote_data",
@@ -1067,9 +1167,10 @@
       // append commas between both fields and fieldnames
       insert_string.append(',');
       values_string.append(',');
-    DBUG_PRINT("ha_federated::write_row", 
-               ("insert_string %s values_string %s insert_field_value_string %s", 
-                insert_string.c_ptr_quick(), values_string.c_ptr_quick(),
insert_field_value_string.c_ptr_quick()));
+      DBUG_PRINT("ha_federated::write_row", 
+         ("insert_string %s values_string %s insert_field_value_string %s", 
+         insert_string.c_ptr_quick(), values_string.c_ptr_quick(),
+         insert_field_value_string.c_ptr_quick()));
 
     }
   }
@@ -1365,30 +1466,55 @@
                                __attribute__((unused)))
 {
   char index_value[IO_SIZE];
+  char key_value[IO_SIZE];
+  char test_value[IO_SIZE];
   String index_string(index_value, sizeof(index_value), &my_charset_bin);
+  String test_string(test_value, sizeof(test_value), &my_charset_bin);
   index_string.length(0);
+  test_string.length(0);
+  uint keylen;
 
   char sql_query_buffer[IO_SIZE];
+  String tmp_string;
   String sql_query(sql_query_buffer, sizeof(sql_query_buffer), &my_charset_bin);
   sql_query.length(0);
 
   DBUG_ENTER("ha_federated::index_read_idx");
  
statistic_increment(table->in_use->status_var.ha_read_key_count,&LOCK_status);
 
-  index_string.length(0);
-  sql_query.length(0);
-
   sql_query.append(share->select_query);
   sql_query.append(" WHERE ");
   sql_query.append(table->key_info[index].key_part->field->field_name);
   sql_query.append(" = ");
 
-  table->key_info[index].key_part->field->val_str(&index_string, (char
*)(key));
+  if (table->key_info[index].key_part->field->type() == MYSQL_TYPE_VARCHAR) 
+  {
+    //keylen= uint2korr(key);
+    keylen= key[0];
+    create_where_from_key(&tmp_string, &table->key_info[index], key, keylen);
+    memcpy(key_value, key + HA_KEY_BLOB_LENGTH, keylen);
+    key_value[keylen]= 0;
+    DBUG_PRINT("ha_federated::index_read_idx",
+      ("key_value %s len %d", key_value, keylen));
+    index_string.append(key_value);
+  }
+  else
+  {
+    //table->key_info[index].key_part->field->val_str(&index_string, (char
+    //*)(key));
+    index_string.append((char *)(key));
+  }
+  DBUG_PRINT("ha_federated::index_read_idx",
+    ("current key %d key value %s index_string value %s length %d", index, (char
*)(key),index_string.c_ptr_quick(),
+     index_string.length()));
+
+  //table->key_info[index].key_part->field->val_str(&index_string);
   quote_data(&index_string, table->key_info[index].key_part->field);
   sql_query.append(index_string);
 
   DBUG_PRINT("ha_federated::index_read_idx",
-             ("sql_query %s", sql_query.c_ptr_quick()));
+    ("current position %d sql_query %s", current_position, 
+     sql_query.c_ptr_quick()));
 
   if (mysql_real_query(mysql, sql_query.c_ptr_quick(), sql_query.length()))
   {
@@ -1539,7 +1665,7 @@
 {
   DBUG_ENTER("ha_federated::rnd_pos");
  
statistic_increment(table->in_use->status_var.ha_read_rnd_count,&LOCK_status);
-  memcpy(current_position, pos, sizeof(MYSQL_ROW_OFFSET)); // pos is not aligned
+  memcpy_fixed(&current_position, pos, sizeof(MYSQL_ROW_OFFSET)); // pos is not
aligned
   result->current_row= 0;
   result->data_cursor= current_position;
   DBUG_RETURN(rnd_next(buf));

--- 1.2/sql/ha_federated.h	Thu Dec 16 19:08:12 2004
+++ 1.3/sql/ha_federated.h	Thu Jan 13 18:21:36 2005
@@ -75,6 +75,7 @@
   uint convert_row_to_internal_format(byte *buf, MYSQL_ROW row);
   uint type_quote(int type); 
   void quote_data(String *string1, Field *field);
+  bool ha_federated::create_where_from_key(String *to, KEY *key_info, const byte *key,
uint key_length); 
 
 public:
   ha_federated(TABLE *table): handler(table),
Thread
bk commit into 5.0 tree (patg:1.1776)Patrick Galbraith14 Jan