List:Commits« Previous MessageNext Message »
From:Mayank Prasad Date:February 2 2012 3:59pm
Subject:bzr push into mysql-trunk-wl5767 branch (mayank.prasad:3423 to 3424) WL#5767
View as plain text  
 3424 Mayank Prasad	2012-02-02
      WL#5767 : Performance Schema, statements digest
      
      Details:
      - Modified printed reduced token for digest text as per new
        specification. Modified code comments as well.
      - Removed TOK_PFS_ROW_POSSIBLE_SINGLE_VALUE,
        TOK_PFS_ROW_POSSIBLE_MULTIPLE_VALUE
      - Made READ/STORE(_TOKEN) & READ/STORE(_IDENTIFIER) etc to
        inline function.
      - Modified structure PFS_statements_digest_stat as per comments.

    modified:
      storage/perfschema/gen_pfs_lex_token.cc
      storage/perfschema/pfs_digest.cc
      storage/perfschema/pfs_digest.h
 3423 Mayank Prasad	2012-02-02
      WL#5767 Performance Schema, Statements Digest
      
      Details:
      - Implemented FIRST_SEEN/LAST_SEEN, Column. Getting Wrong
        dates, need to see.
      - Changed Digest COLUMN size from varchar(64) to varchar(32).
      - tried to fix statements_digest_long_query by specifying 
        big value of thread_stack.

    modified:
      mysql-test/suite/perfschema/r/dml_esms_by_digest.result
      mysql-test/suite/perfschema/r/pfs_upgrade.result
      mysql-test/suite/perfschema/r/schema.result
      mysql-test/suite/perfschema/r/table_schema.result
      mysql-test/suite/perfschema/t/statements_digest_long_query-master.opt
      scripts/mysql_system_tables.sql
      storage/perfschema/pfs_digest.cc
      storage/perfschema/pfs_digest.h
      storage/perfschema/pfs_engine_table.cc
      storage/perfschema/pfs_engine_table.h
      storage/perfschema/table_esms_by_digest.cc
      storage/perfschema/table_esms_by_digest.h
      storage/perfschema/table_events_statements.cc
=== modified file 'storage/perfschema/gen_pfs_lex_token.cc'
--- a/storage/perfschema/gen_pfs_lex_token.cc	2012-01-04 10:31:04 +0000
+++ b/storage/perfschema/gen_pfs_lex_token.cc	2012-02-02 15:57:35 +0000
@@ -49,10 +49,8 @@ char char_tokens[256];
 
 int tok_pfs_generic_value= 0;
 int tok_pfs_generic_value_list= 0;
-int tok_pfs_row_possible_single_value= 0;
 int tok_pfs_row_single_value= 0;
 int tok_pfs_row_single_value_list= 0;
-int tok_pfs_row_possible_multiple_value= 0;
 int tok_pfs_row_multiple_value= 0;
 int tok_pfs_row_multiple_value_list= 0;
 int tok_pfs_unused= 0;
@@ -179,35 +177,27 @@ void compute_tokens()
 
   max_token_seen++;
   tok_pfs_generic_value= max_token_seen;
-  set_token(tok_pfs_generic_value, "#");
+  set_token(tok_pfs_generic_value, "?");
 
   max_token_seen++;
   tok_pfs_generic_value_list= max_token_seen;
-  set_token(tok_pfs_generic_value_list, "#,#");
-
-  max_token_seen++;
-  tok_pfs_row_possible_single_value= max_token_seen;
-  set_token(tok_pfs_row_possible_single_value, "(#");
+  set_token(tok_pfs_generic_value_list, "?, ...");
 
   max_token_seen++;
   tok_pfs_row_single_value= max_token_seen;
-  set_token(tok_pfs_row_single_value, "(#)");
+  set_token(tok_pfs_row_single_value, "(?)");
 
   max_token_seen++;
   tok_pfs_row_single_value_list= max_token_seen;
-  set_token(tok_pfs_row_single_value_list, "(#),(#)");
-
-  max_token_seen++;
-  tok_pfs_row_possible_multiple_value= max_token_seen;
-  set_token(tok_pfs_row_possible_multiple_value, "(#,#");
+  set_token(tok_pfs_row_single_value_list, "(?) /* , ... */");
 
   max_token_seen++;
   tok_pfs_row_multiple_value= max_token_seen;
-  set_token(tok_pfs_row_multiple_value, "(#,#)");
+  set_token(tok_pfs_row_multiple_value, "(...)");
 
   max_token_seen++;
   tok_pfs_row_multiple_value_list= max_token_seen;
-  set_token(tok_pfs_row_multiple_value_list, "(#,#),(#,#)");
+  set_token(tok_pfs_row_multiple_value_list, "(...) /* , ... */");
 
   max_token_seen++;
   tok_pfs_unused= max_token_seen;
@@ -243,10 +233,8 @@ void print_tokens()
   printf("/* PFS specific tokens. */\n");
   printf("#define TOK_PFS_GENERIC_VALUE %d\n", tok_pfs_generic_value);
   printf("#define TOK_PFS_GENERIC_VALUE_LIST %d\n", tok_pfs_generic_value_list);
-  printf("#define TOK_PFS_ROW_POSSIBLE_SINGLE_VALUE %d\n", tok_pfs_row_possible_single_value);
   printf("#define TOK_PFS_ROW_SINGLE_VALUE %d\n", tok_pfs_row_single_value);
   printf("#define TOK_PFS_ROW_SINGLE_VALUE_LIST %d\n", tok_pfs_row_single_value_list);
-  printf("#define TOK_PFS_ROW_POSSIBLE_MULTIPLE_VALUE %d\n", tok_pfs_row_possible_multiple_value);
   printf("#define TOK_PFS_ROW_MULTIPLE_VALUE %d\n", tok_pfs_row_multiple_value);
   printf("#define TOK_PFS_ROW_MULTIPLE_VALUE_LIST %d\n", tok_pfs_row_multiple_value_list);
   printf("#define TOK_PFS_UNUSED %d\n", tok_pfs_unused);

=== modified file 'storage/perfschema/pfs_digest.cc'
--- a/storage/perfschema/pfs_digest.cc	2012-02-02 12:04:43 +0000
+++ b/storage/perfschema/pfs_digest.cc	2012-02-02 15:57:35 +0000
@@ -44,101 +44,6 @@
   <SELECT_TOKEN><*><FROM_TOKEN><ID_TOKEN><2><T1>
 */
 
-/** 
-  Macro to read a single token from token array.
-*/
-#define READ_TOKEN(_dest, _index, _src)                                \
-{                                                                      \
-  short _sh;                                                           \
-  _sh= ((0x00ff & _src[_index+1])<<8) | (0x00ff & _src[_index]);       \
-  _dest= (int)(_sh);                                                   \
-  _index+= PFS_SIZE_OF_A_TOKEN;                                        \
-}
-
-/**
-  Macro to store a single token in token array.
-*/
-#define STORE_TOKEN(_dest, _index, _token)                             \
-{                                                                      \
-  short _sh= (short)_token;                                            \
-  _dest[_index++]= (_sh) & 0xff;                                       \
-  _dest[_index++]= (_sh>>8) & 0xff;                                    \
-}
-
-/**
-  Macro to read an identifier from token array.
-*/
-#define READ_IDENTIFIER(_dest, _index, _src)                           \
-{                                                                      \
-  int _length;                                                         \
-  int remaining_bytes= PFS_MAX_DIGEST_STORAGE_SIZE-_index;             \
-  DBUG_ASSERT(remaining_bytes >= 0);                                   \
-  /*                                                                   \
-    Read ID's length.                                                  \
-    Make sure that space, to read ID's length, is available.           \
-  */                                                                   \
-  if(remaining_bytes >= PFS_SIZE_OF_A_TOKEN)                           \
-  {                                                                    \
-    READ_TOKEN(_length, _index, _src);                                 \
-    /*                                                                 \
-      While storing ID length, it has already been stored              \
-      in a way that ID doesn't go beyond the storage size,             \
-      so no need to check length here.                                 \
-    */                                                                 \
-    strncpy(_dest, _src+_index, _length);                              \
-    _index+= _length;                                                  \
-    _dest+= _length;                                                   \
-  }                                                                    \
-}
-
-/**
-  Macro to store an identifier in token array.
-*/
-#define STORE_IDENTIFIER(_dest, _index, _length, _id)                  \
-{                                                                      \
-  int remaining_bytes= PFS_MAX_DIGEST_STORAGE_SIZE-_index;             \
-  DBUG_ASSERT(remaining_bytes >= 0);                                   \
-  /*                                                                   \
-    Store ID's length.                                                 \
-    Make sure that space, to store ID's length, is available.          \
-  */                                                                   \
-  if(remaining_bytes >= PFS_SIZE_OF_A_TOKEN)                           \
-  {                                                                    \
-    /*                                                                 \
-       Make sure to store ID length/ID as per the space                \
-       available.                                                      \
-    */                                                                 \
-    remaining_bytes-= PFS_SIZE_OF_A_TOKEN;                             \
-    _length= _length>remaining_bytes?remaining_bytes:_length;          \
-    STORE_TOKEN(_dest, _index, _length);                               \
-    strncpy(_dest+_index, _id, _length);                               \
-    _index+= _length;                                                  \
-  }                                                                    \
-}
-
-/**
-  Macro to read last two tokens from token array. If an identifier
-  is found, do not look for token after that.
-*/
-#define READ_LAST_TWO_TOKENS(_t1, _t2, _id_index, _byte_count)         \
-{                                                                      \
-  int _last_token_index;                                               \
-  if(_id_index <= _byte_count - PFS_SIZE_OF_A_TOKEN)                   \
-  {                                                                    \
-    /* Take last token. */                                             \
-    _last_token_index= _byte_count - PFS_SIZE_OF_A_TOKEN;              \
-    DBUG_ASSERT(_last_token_index >= 0);                               \
-    READ_TOKEN(_t1, _last_token_index, digest_storage->m_token_array); \
-  }                                                                    \
-  if(_id_index <= _byte_count - 2*PFS_SIZE_OF_A_TOKEN)                 \
-  {                                                                    \
-    /* Take 2nd token from last. */                                    \
-    _last_token_index= _byte_count - 2*PFS_SIZE_OF_A_TOKEN;            \
-    DBUG_ASSERT(_last_token_index >= 0);                               \
-    READ_TOKEN(_t2, _last_token_index, digest_storage->m_token_array); \
-  }                                                                    \
-}
-
 unsigned int statements_digest_size= 0;
 /** EVENTS_STATEMENTS_HISTORY_LONG circular buffer. */
 PFS_statements_digest_stat *statements_digest_stat_array= NULL;
@@ -373,11 +278,9 @@ void reset_esms_by_digest()
 /*
   This function, iterates token array and updates digest_text.
 */
-void get_digest_text(char* digest_text,
-                            char* token_array,
-                            int byte_count)
+void get_digest_text(char* digest_text, char* token_array, int byte_count)
 {
-  int tok= 0;
+  uint tok= 0;
   int current_byte= 0;
   char *digest_text_start= digest_text;
   lex_token_string *tok_data;
@@ -387,30 +290,15 @@ void get_digest_text(char* digest_text,
   while(current_byte<byte_count &&
         (digest_text-digest_text_start)<COL_DIGEST_TEXT_SIZE-3)
   {
-    READ_TOKEN(tok, current_byte, token_array);
+    read_token(&tok, &current_byte, token_array);
     tok_data= & lex_token_array[tok];
 
     switch (tok)
     {
-    /* All literals are printed as '?' */
-    case BIN_NUM:
-    case DECIMAL_NUM:
-    case FLOAT_NUM:
-    case HEX_NUM:
-    case LEX_HOSTNAME:
-    case LONG_NUM:
-    case NUM:
-    case NCHAR_STRING:
-    case TEXT_STRING:
-    case ULONGLONG_NUM:
-      *digest_text= '?';
-      digest_text++;
-      break;
-
     /* All identifiers are printed with their name. */
     case IDENT:
     case IDENT_QUOTED:
-      READ_IDENTIFIER(digest_text, current_byte, token_array);
+      read_identifier(&digest_text, &current_byte, token_array);
       *digest_text= ' ';
       digest_text++;
       break;
@@ -526,9 +414,7 @@ void pfs_digest_add_token_v1(PSI_digest_
   uint last_token = TOK_PFS_UNUSED;
   uint last_token2= TOK_PFS_UNUSED;
   
-  READ_LAST_TWO_TOKENS(last_token, last_token2,
-                       digest_storage->m_last_id_index,
-                       digest_storage->m_byte_count);
+  read_last_two_tokens(digest_storage, &last_token, &last_token2);
 
   switch (token)
   {
@@ -568,7 +454,7 @@ void pfs_digest_add_token_v1(PSI_digest_
       /*
         Add this token or the resulting reduce to digest storage.
       */
-      STORE_TOKEN(digest_storage->m_token_array, digest_storage->m_byte_count, token);
+      store_token(digest_storage, token);
       break;
     }
     case ')':
@@ -578,15 +464,14 @@ void pfs_digest_add_token_v1(PSI_digest_
       { 
         /*
           REDUCE:
-            "(" "#" +  ")" => "(#)"
+          TOK_PFS_ROW_SINGLE_VALUE :=
+            '(' TOK_PFS_GENERIC_VALUE ')' 
         */
         digest_storage->m_byte_count-= 2*PFS_SIZE_OF_A_TOKEN;
         token= TOK_PFS_ROW_SINGLE_VALUE;
       
         /* Read last two tokens again */
-        READ_LAST_TWO_TOKENS(last_token, last_token2,
-                             digest_storage->m_last_id_index,
-                             digest_storage->m_byte_count);
+        read_last_two_tokens(digest_storage, &last_token, &last_token2);
 
         if((last_token2 == TOK_PFS_ROW_SINGLE_VALUE ||
             last_token2 == TOK_PFS_ROW_SINGLE_VALUE_LIST) &&
@@ -594,9 +479,12 @@ void pfs_digest_add_token_v1(PSI_digest_
         {
           /*
             REDUCE:
-              "(#)" "," + "(#)" => "(#),(#)"
+            TOK_PFS_ROW_SINGLE_VALUE_LIST := 
+              TOK_PFS_ROW_SINGLE_VALUE ',' TOK_PFS_ROW_SINGLE_VALUE
+
             REDUCE:
-              "(#),(#)" "," + "(#)" => "(#),(#)"
+            TOK_PFS_ROW_SINGLE_VALUE_LIST := 
+              TOK_PFS_ROW_SINGLE_VALUE_LIST ',' TOK_PFS_ROW_SINGLE_VALUE
           */
           digest_storage->m_byte_count-= 2*PFS_SIZE_OF_A_TOKEN;
           token= TOK_PFS_ROW_SINGLE_VALUE_LIST;
@@ -607,15 +495,14 @@ void pfs_digest_add_token_v1(PSI_digest_
       {
         /*
           REDUCE:
-            "(" "#,#" + ")" => "(#,#)"
+          TOK_PFS_ROW_MULTIPLE_VALUE :=
+            '(' TOK_PFS_GENERIC_VALUE_LIST ')'
         */
         digest_storage->m_byte_count-= 2*PFS_SIZE_OF_A_TOKEN;
         token= TOK_PFS_ROW_MULTIPLE_VALUE;
 
         /* Read last two tokens again */
-        READ_LAST_TWO_TOKENS(last_token, last_token2,
-                             digest_storage->m_last_id_index,
-                             digest_storage->m_byte_count);
+        read_last_two_tokens(digest_storage, &last_token, &last_token2);
 
         if((last_token2 == TOK_PFS_ROW_MULTIPLE_VALUE ||
             last_token2 == TOK_PFS_ROW_MULTIPLE_VALUE_LIST) &&
@@ -623,9 +510,12 @@ void pfs_digest_add_token_v1(PSI_digest_
         {
           /*
             REDUCE:
-              "(#,#)" "," + "(#,#)" ) => "(#,#),(#,#)"
+            TOK_PFS_ROW_MULTIPLE_VALUE_LIST :=
+              TOK_PFS_ROW_MULTIPLE_VALUE ',' TOK_PFS_ROW_MULTIPLE_VALUE
+
             REDUCE:
-              "(#,#),(#,#)" "," + "(#,#)" ) => "(#,#),(#,#)"
+            TOK_PFS_ROW_MULTIPLE_VALUE_LIST :=
+              TOK_PFS_ROW_MULTIPLE_VALUE_LIST ',' TOK_PFS_ROW_MULTIPLE_VALUE
           */
           digest_storage->m_byte_count-= 2*PFS_SIZE_OF_A_TOKEN;
           token= TOK_PFS_ROW_MULTIPLE_VALUE_LIST;
@@ -634,7 +524,7 @@ void pfs_digest_add_token_v1(PSI_digest_
       /*
         Add this token or the resulting reduce to digest storage.
       */
-      STORE_TOKEN(digest_storage->m_token_array, digest_storage->m_byte_count, token);
+      store_token(digest_storage, token);
       break;
     }
     case IDENT:
@@ -643,11 +533,11 @@ void pfs_digest_add_token_v1(PSI_digest_
       /*
         Add this token to digest storage.
       */
-      STORE_TOKEN(digest_storage->m_token_array, digest_storage->m_byte_count, token);
+      store_token(digest_storage, token);
       /*
         Add this identifier's lenght and string to digest storage.
       */
-      STORE_IDENTIFIER(digest_storage->m_token_array, digest_storage->m_byte_count, yylen, yytext);
+      store_identifier(digest_storage, yylen, yytext);
       /* 
         Update the index of last identifier found.
       */
@@ -659,7 +549,7 @@ void pfs_digest_add_token_v1(PSI_digest_
       /*
         Add this token to digest storage.
       */
-      STORE_TOKEN(digest_storage->m_token_array, digest_storage->m_byte_count, token);
+      store_token(digest_storage, token);
       break;
     }
   }

=== modified file 'storage/perfschema/pfs_digest.h'
--- a/storage/perfschema/pfs_digest.h	2012-02-02 12:04:43 +0000
+++ b/storage/perfschema/pfs_digest.h	2012-02-02 15:57:35 +0000
@@ -55,15 +55,16 @@ struct {
 struct PFS_statements_digest_stat
 {
   /**
-    Digest Storage.
-  */
-  PFS_digest_storage m_digest_storage;
-  /**
     Digest hash/LF Hash search key.
   */
   PFS_digest_hash m_md5_hash;
 
   /**
+    Digest Storage.
+  */
+  PFS_digest_storage m_digest_storage;
+
+  /**
     Statement stat.
   */
   PFS_statement_stat m_stat;
@@ -75,8 +76,6 @@ struct PFS_statements_digest_stat
   ulonglong m_last_seen;
 };
 
-
-
 int init_digest(unsigned int digest_sizing);
 void cleanup_digest();
 
@@ -103,4 +102,113 @@ void pfs_digest_add_token_v1(PSI_digest_
                              int yylen);
 void pfs_digest_end_v1(PSI_digest_locker *locker);
 
+
+
+/** 
+  Function to read a single token from token array.
+*/
+inline void read_token(uint *dest, int *index, char *src)
+{
+  unsigned short sh;
+  sh= ((0x00ff & src[*index + 1])<<8) | (0x00ff & src[*index]);
+  *dest= (uint)(sh);
+  *index= *index + PFS_SIZE_OF_A_TOKEN;
+}
+
+/**
+  Function to store a single token in token array.
+*/
+inline void store_token(PFS_digest_storage* digest_storage, uint token)
+{
+  char* dest= digest_storage->m_token_array;
+  int* index= &digest_storage->m_byte_count;
+  unsigned short sh= (unsigned short)token;
+
+  dest[*index]= (sh) & 0xff;
+  *index= *index + 1;
+  dest[*index]= (sh>>8) & 0xff;
+  *index= *index + 1;
+}
+
+/**
+  Function to read an identifier from token array.
+*/
+inline void read_identifier(char **dest, int *index, char *src)
+{
+  uint length;
+  int remaining_bytes= PFS_MAX_DIGEST_STORAGE_SIZE - *index;
+  DBUG_ASSERT(remaining_bytes >= 0);
+  /*
+    Read ID's length.
+    Make sure that space, to read ID's length, is available.
+  */
+  if(remaining_bytes >= PFS_SIZE_OF_A_TOKEN)
+  {
+    read_token(&length, index, src);
+    /*
+      While storing ID length, it has already been stored
+      in a way that ID doesn't go beyond the storage size,
+      so no need to check length here.
+    */
+    strncpy(*dest, src + *index, length);
+    *index= *index + length;
+    *dest= *dest + length;
+  }
+}
+
+/**
+  Function to store an identifier in token array.
+*/
+inline void store_identifier(PFS_digest_storage* digest_storage,
+                             uint id_length, char *id_name)
+{
+  char* dest= digest_storage->m_token_array;
+  int* index= &digest_storage->m_byte_count;
+  int remaining_bytes= PFS_MAX_DIGEST_STORAGE_SIZE - *index;
+  DBUG_ASSERT(remaining_bytes >= 0);
+
+  /*
+    Store ID's length.
+    Make sure that space, to store ID's length, is available.
+  */
+  if(remaining_bytes >= PFS_SIZE_OF_A_TOKEN)
+  {
+    /*
+       Make sure to store ID length/ID as per the space available.
+    */
+    remaining_bytes-= PFS_SIZE_OF_A_TOKEN;
+    id_length= id_length>(uint)remaining_bytes?(uint)remaining_bytes:id_length;
+    store_token(digest_storage, id_length);
+    strncpy(dest + *index, id_name, id_length);
+    *index= *index + id_length;
+  }
+}
+
+/**
+  Function to read last two tokens from token array. If an identifier
+  is found, do not look for token after that.
+*/
+inline void read_last_two_tokens(PFS_digest_storage* digest_storage,
+                                 uint *t1, uint *t2)
+{
+  int last_token_index;
+  int last_id_index= digest_storage->m_last_id_index;
+  int byte_count= digest_storage->m_byte_count;
+
+  if(last_id_index <= byte_count - PFS_SIZE_OF_A_TOKEN)
+  {
+    /* Take last token. */
+    last_token_index= byte_count - PFS_SIZE_OF_A_TOKEN;
+    DBUG_ASSERT(last_token_index >= 0);
+    read_token(t1, &last_token_index, digest_storage->m_token_array);
+  }
+  if(last_id_index <= byte_count - 2*PFS_SIZE_OF_A_TOKEN)
+  {
+    /* Take 2nd token from last. */
+    last_token_index= byte_count - 2*PFS_SIZE_OF_A_TOKEN;
+    DBUG_ASSERT(last_token_index >= 0);
+    read_token(t2, &last_token_index, digest_storage->m_token_array);
+  }
+}
+
 #endif

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-wl5767 branch (mayank.prasad:3423 to 3424) WL#5767Mayank Prasad3 Feb