3437 Marc Alff 2012-02-09
Revised the add_token interface
modified:
include/mysql/psi/psi.h
include/mysql/psi/psi_abi_v0.h.pp
include/mysql/psi/psi_abi_v1.h.pp
include/mysql/psi/psi_abi_v2.h.pp
mysys/psi_noop.c
sql/sql_lex.cc
storage/perfschema/pfs_digest.cc
storage/perfschema/pfs_digest.h
3436 Mayank Prasad 2012-02-08
WL#5767 : Performance Schema, Statements Digest
Details:
- Modified PASS_TOKEN_TO_PS.
- Modified test cases result files accordingly.
modified:
mysql-test/suite/perfschema/r/statements_digest.result
mysql-test/suite/perfschema/r/statements_digest_long_query.result
sql/sql_lex.cc
=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h 2012-02-08 10:30:58 +0000
+++ b/include/mysql/psi/psi.h 2012-02-09 14:41:43 +0000
@@ -43,6 +43,18 @@
C_MODE_START
struct TABLE_SHARE;
+/*
+ There are 3 known bison parsers in the server:
+ - (1) the SQL parser itself, sql/sql_yacc.yy
+ - (2) storage/innobase/fts/fts0pars.y
+ - (3) storage/innobase/pars/pars0grm.y
+ What is instrumented here are the tokens from the SQL query text (1),
+ to make digests.
+ Now, to avoid name pollution and conflicts with different YYSTYPE definitions,
+ an opaque structure is used here.
+ The real type to use when invoking the digest api is LEX_YYSTYPE.
+*/
+struct OPAQUE_LEX_YYSTYPE;
/**
@file mysql/psi/psi.h
@@ -1836,7 +1848,7 @@ typedef struct PSI_digest_locker * (*dig
(struct PSI_statement_locker *locker);
typedef struct PSI_digest_locker* (*digest_add_token_v1_t)
- (struct PSI_digest_locker *locker, uint token, char *yytext, int yylen);
+ (struct PSI_digest_locker *locker, uint token, struct OPAQUE_LEX_YYSTYPE *yylval);
/**
Performance Schema Interface, version 1.
=== modified file 'include/mysql/psi/psi_abi_v0.h.pp'
--- a/include/mysql/psi/psi_abi_v0.h.pp 2012-01-06 09:03:53 +0000
+++ b/include/mysql/psi/psi_abi_v0.h.pp 2012-02-09 14:41:43 +0000
@@ -1,6 +1,7 @@
#include "mysql/psi/psi.h"
C_MODE_START
struct TABLE_SHARE;
+struct OPAQUE_LEX_YYSTYPE;
struct PSI_mutex;
typedef struct PSI_mutex PSI_mutex;
struct PSI_rwlock;
=== modified file 'include/mysql/psi/psi_abi_v1.h.pp'
--- a/include/mysql/psi/psi_abi_v1.h.pp 2012-02-06 09:30:53 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp 2012-02-09 14:41:43 +0000
@@ -1,6 +1,7 @@
#include "mysql/psi/psi.h"
C_MODE_START
struct TABLE_SHARE;
+struct OPAQUE_LEX_YYSTYPE;
struct PSI_mutex;
typedef struct PSI_mutex PSI_mutex;
struct PSI_rwlock;
@@ -488,7 +489,7 @@ typedef void (*set_socket_thread_owner_v
typedef struct PSI_digest_locker * (*digest_start_v1_t)
(struct PSI_statement_locker *locker);
typedef struct PSI_digest_locker* (*digest_add_token_v1_t)
- (struct PSI_digest_locker *locker, uint token, char *yytext, int yylen);
+ (struct PSI_digest_locker *locker, uint token, struct OPAQUE_LEX_YYSTYPE *yylval);
struct PSI_v1
{
register_mutex_v1_t register_mutex;
=== modified file 'include/mysql/psi/psi_abi_v2.h.pp'
--- a/include/mysql/psi/psi_abi_v2.h.pp 2012-01-09 09:09:26 +0000
+++ b/include/mysql/psi/psi_abi_v2.h.pp 2012-02-09 14:41:43 +0000
@@ -1,6 +1,7 @@
#include "mysql/psi/psi.h"
C_MODE_START
struct TABLE_SHARE;
+struct OPAQUE_LEX_YYSTYPE;
struct PSI_mutex;
typedef struct PSI_mutex PSI_mutex;
struct PSI_rwlock;
=== modified file 'mysys/psi_noop.c'
--- a/mysys/psi_noop.c 2012-02-03 16:00:30 +0000
+++ b/mysys/psi_noop.c 2012-02-09 14:41:43 +0000
@@ -616,9 +616,8 @@ digest_start_noop(PSI_statement_locker *
}
static PSI_digest_locker* digest_add_token_noop(PSI_digest_locker *locker NNN,
- uint token NNN,
- char *yytext NNN,
- int yylen NNN)
+ uint token NNN,
+ struct OPAQUE_LEX_YYSTYPE *yylval NNN)
{
return NULL;
}
=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc 2012-02-08 11:51:37 +0000
+++ b/sql/sql_lex.cc 2012-02-09 14:41:43 +0000
@@ -33,21 +33,24 @@
#include "sql_optimizer.h" // JOIN
#ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
-#define PASS_TOKEN_TO_PS(_token, _yylval) \
- /*
- Passing token to PS function to calculate statement digest
- for this statement.
- */ \
- if(lip->m_digest_psi != NULL) \
- { \
- lip->m_digest_psi= PSI_CALL(digest_add_token)(lip->m_digest_psi, \
- _token, \
- _yylval->lex_str.str, \
- _yylval->lex_str.length); \
+#define PSI_ADD_TOKEN(L, T, Y) inline_add_token(L, T, Y)
+
+static void inline_add_token(Lex_input_stream *lip,
+ uint token,
+ YYSTYPE *yylval)
+{
+ if (lip->m_digest_psi != NULL)
+ {
+ /*
+ Passing token to PS function to calculate statement digest
+ for this statement.
+ */
+ lip->m_digest_psi= PSI_CALL(digest_add_token)
+ (lip->m_digest_psi, token, (OPAQUE_LEX_YYSTYPE*) yylval);
}
+}
#else
-#define PASS_TOKEN_TO_PS(_token, _yylval) \
- do{}while(0);
+#define PSI_ADD_TOKEN(L, T, Y) do {} while(0)
#endif
static int lex_one_token(void *arg, void *yythd);
@@ -900,7 +903,7 @@ int MYSQLlex(void *arg, void *yythd)
lip->lookahead_token= -1;
*yylval= *(lip->lookahead_yylval);
lip->lookahead_yylval= NULL;
- PASS_TOKEN_TO_PS(token, yylval);
+ PSI_ADD_TOKEN(lip, token, yylval);
return token;
}
@@ -918,10 +921,10 @@ int MYSQLlex(void *arg, void *yythd)
token= lex_one_token(arg, yythd);
switch(token) {
case CUBE_SYM:
- PASS_TOKEN_TO_PS(WITH_CUBE_SYM, yylval);
+ PSI_ADD_TOKEN(lip, WITH_CUBE_SYM, yylval);
return WITH_CUBE_SYM;
case ROLLUP_SYM:
- PASS_TOKEN_TO_PS(WITH_ROLLUP_SYM, yylval);
+ PSI_ADD_TOKEN(lip, WITH_ROLLUP_SYM, yylval);
return WITH_ROLLUP_SYM;
default:
/*
@@ -930,7 +933,7 @@ int MYSQLlex(void *arg, void *yythd)
lip->lookahead_yylval= lip->yylval;
lip->yylval= NULL;
lip->lookahead_token= token;
- PASS_TOKEN_TO_PS(WITH, yylval);
+ PSI_ADD_TOKEN(lip, WITH, yylval);
return WITH;
}
break;
@@ -938,7 +941,7 @@ int MYSQLlex(void *arg, void *yythd)
break;
}
- PASS_TOKEN_TO_PS(token, yylval);
+ PSI_ADD_TOKEN(lip, token, yylval);
return token;
}
=== modified file 'storage/perfschema/pfs_digest.cc'
--- a/storage/perfschema/pfs_digest.cc 2012-02-06 12:08:15 +0000
+++ b/storage/perfschema/pfs_digest.cc 2012-02-09 14:41:43 +0000
@@ -18,6 +18,10 @@
Statement Digest data structures (implementation).
*/
+/*
+ This code needs extra visibility in the lexer structures
+*/
+
#include "my_global.h"
#include "my_sys.h"
#include "pfs_instr.h"
@@ -25,13 +29,21 @@
#include "pfs_global.h"
#include "table_helper.h"
#include "my_md5.h"
+#include "sql_lex.h"
+#include "sql_get_diagnostics.h"
#include <string.h>
/* Generated code */
-#define YYSTYPE_IS_DECLARED
#include "sql_yacc.h"
#include "pfs_lex_token.h"
+/* Name pollution from sql/sql_lex.h */
+#ifdef LEX_YYSTYPE
+#undef LEX_YYSTYPE
+#endif
+
+#define LEX_YYSTYPE YYSTYPE
+
/**
Token array :
Token array is an array of bytes to store tokens recieved during parsing.
@@ -439,8 +451,7 @@ struct PSI_digest_locker* pfs_digest_sta
PSI_digest_locker* pfs_digest_add_token_v1(PSI_digest_locker *locker,
uint token,
- char *yytext,
- int yylen)
+ OPAQUE_LEX_YYSTYPE *yylval)
{
PSI_digest_locker_state *state= NULL;
PFS_events_statements *pfs= NULL;
@@ -588,12 +599,16 @@ PSI_digest_locker* pfs_digest_add_token_
case IDENT:
case IDENT_QUOTED:
{
+ LEX_YYSTYPE *lex_token= (LEX_YYSTYPE*) yylval;
+ char *yytext= lex_token->lex_str.str;
+ int yylen= lex_token->lex_str.length;
+
/*
Add this token to digest storage.
*/
store_token(digest_storage, token);
/*
- Add this identifier's lenght and string to digest storage.
+ Add this identifier's length and string to digest storage.
*/
store_identifier(digest_storage, yylen, yytext);
/*
=== modified file 'storage/perfschema/pfs_digest.h'
--- a/storage/perfschema/pfs_digest.h 2012-02-06 12:08:15 +0000
+++ b/storage/perfschema/pfs_digest.h 2012-02-09 14:41:43 +0000
@@ -98,8 +98,7 @@ extern PFS_statements_digest_stat *state
struct PSI_digest_locker* pfs_digest_start_v1(PSI_statement_locker *locker);
PSI_digest_locker* pfs_digest_add_token_v1(PSI_digest_locker *locker,
uint token,
- char *yytext,
- int yylen);
+ OPAQUE_LEX_YYSTYPE *yylval);
/**
Function to read a single token from token array.
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-trunk-wl5767 branch (marc.alff:3436 to 3437) | Marc Alff | 10 Feb |