MySQL:如何编写Information Schema Plugin(9)
const char**ptr, *output[] = {"hello", "world", "this", "is","a", "test", 0};
int num;
/*声明变量*/
LOOKUP_FIELD_VALUESlookups;
bzero((char*)&lookups, sizeof(lookups));
/*调用函数获得COND中定义的条件*/
if (calc_lookup_values_from_cond(thd, cond, tables,&lookups))
return 0;
for (num = 0,ptr = output; *ptr; ptr++)
{
if (lookups.value1.str &&
my_strnncoll(cs, (const uchar*)*ptr, strlen(*ptr),
(const uchar*)lookups.value1.str,
lookups.value1.length))
continue;
/*只有满足条件的字符串才会被存储到table中*/
table->field[0]->store(++num);
table->field[1]->store(*ptr, strlen(*ptr), cs);
if (schema_table_store_record(thd, table))
return 1;
}
return 0;
}
/*初始化i_s plugin*/
int cond_push_init(void *p)
{
ST_SCHEMA_TABLE*schema = (ST_SCHEMA_TABLE*) p;
/*指定表定义*/
schema->fields_info= cond_push_fields;
/*指定记录填充函数*/
schema->fill_table= fill_cond_push;
schema->idx_field1= 1;
return 0;
}
struct st_mysql_information_schemacond_push=
{MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
mysql_declare_plugin(cond_push)
{
MYSQL_INFORMATION_SCHEMA_PLUGIN,
&cond_push,
"COND_PUSH",
"AndrewHutchings (Andrew.Hutchings@Sun.COM)",
"A simplecondition pushdown demo table",
PLUGIN_LICENSE_GPL,
cond_push_init,
NULL,
0x0010,
NULL,
NULL,
NULL
}
mysql_declare_plugin_end;
5)例子:获取当前query cache中的QUERY信息(摘自网络,略改)
Query_cache中的query 存储在query_cache->queries结构体中,这是一个hash表,我们可以遍历其中的记录还获得想要的数据,代码如下:
view plain
#include <stdlib.h>
#include <ctype.h>
/*内核中一些代码定义在MYSQL_SERVER宏中*/
#ifndef MYSQL_SERVER
#define MYSQL_SERVER
#endif
/*sql_cache.cc中包含了全部跟querycache相关的代码*/
#include <sql_cache.cc>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>