MySQL:如何编写Information Schema Plugin(9)

来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:45 点击:

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> 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • mysql-mmm
  • mysqldump命令——MySQL数据库备份还原
  • Oracle数据导入MySQL的快捷工具:MySQL Migration Toolkit
  • 简简单单储存过程——循环一个select结果集
  • MySQL数据库十大优化技巧
  • Mysql主主复制架构配置
  • Mysql安装笔记
  • Mysql的Procedure 参数为NULL问题分析
  • MySQL Stmt预处理提高效率问题的小研究
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1