mysql整合ignite_apacheignite系列(九):使用ddl和dml脚本初始。。。

k12教育教学网
mysql整合ignite_apacheignite系列(九):使⽤ddl和dml脚本
初始。。。
博客⼜断了⼀段时间,本篇将记录⼀下基于ignite对jdbc⽀持的特性在实际使⽤过程中的使⽤。
使⽤ddl和dml脚本初始化ignite
由于spring-boot中⽀持通过spring.datasource.schema属性指定初始化DDL脚本,spring.datasource.data指定初始化DML脚本。⽽ignite⽀持jdbc协议,测试了⼀下,发现⼀样可以通过该配置初始化ignite。
spring.datasource.url=jdbc:ignite:thin://127.0.0.1/
spring.datasource.driver-class-name=org.apache.ignite.IgniteJdbcThinDriver
spring.datasource.schema=classpath:db/schema.sql
spring.datasource.data=classpath:db/data.sql
说明ignite数据源同样可以作为⼀个DataSource实例
DDL的规范
创建表
CREATE TABLE [IF NOT EXISTS] tableName (tableColumn [, tableColumn]...
[, PRIMARY KEY (columnName [,columnName]...)])
[WITH "paramName=paramValue [,paramName=paramValue]..."]
WITH语法中⽀持的选项以及含义如下(可参见xml配置中CacheConfiguration的相关配置):
参数
含义
TEMPLATE
缓存模式:PARTITIONED或者REPLICATED
BACKUPS
备份数量
ATOMICITY
原⼦模式:ATOMIC或者TRANSACTIONAL
CACHEGROUP
缓存组名
AFFINITYKEY
并置键列名
CACHE_NAME
缓存名(如果不设置的话默认会加SQL_前缀)
西部妈妈网KEY_TYPE
值类型
DATA_REGION
内存区名
创建索引
CREATE [SPATIAL] INDEX [[IF NOT EXISTS] indexName] ON tableName
(columnName [ASC|DESC] [,...]) [(index_option [...])]
⽰例:
schema.sql
--student学⽣信息表
CREATE TABLE IF NOT EXISTS PUBLIC.STUDENT (
STUDID INTEGER,
NAME VARCHAR,
EMAIL VARCHAR,
dob Date,
PRIMARY KEY (STUDID))
WITH "template=replicated,atomicity=ATOMIC,cache_name=student";
CREATE INDEX IF NOT EXISTS STUDENT_NE_INDEX ON PUBLIC.STUDENT (NAME, EMAIL);
-- grade成绩表
CREATE TABLE IF NOT EXISTS PUBLIC.GRADE (
STUDID INTEGER,
grade DOUBLE,
PRIMARY KEY (STUDID))
WITH "template=replicated,atomicity=ATOMIC,cache_name=grade";
DML规范
ignite中dml与标准sql中的基本⼀致⽰例如下:
INSERT INTO student (studid, name, email, dob) VALUES (1, 'student_1', 'student_1gmail', '2017-09-28');完整dml初始化脚本:
-- student
INSERT INTO student (studid, name, email, dob) VALUES (1, 'student_1', 'student_1gmail', '2017-09-28'); INSERT INTO student (studid, name, email, dob) VALUES (2, 'student_2', 'student_2gmail', '2017-09-28'); ...
--grade《国家新型城镇化规划(2014-2020年)》
全球品牌价值百强可以发现缓存和数据均已初始化成功。
使⽤Mybatis查询ignite缓存
由于ignite可以作为DataSource的实例,所以猜想应该也可以通过Mybatis去查询ignite,这样可以替代
原来需要SqlFieldsQuery查询并对结果进⾏逐⾏解析的⽅式。经验证后发现ignite能完美⽀持myabtis,所以在查询ignite的⽅式上有了⼀个更便捷的⽅式。
与普通使⽤mybatis的⽅式⼀样,定义l和IgniteMapper.java
* 根据studentId查询学⽣信息
* @param studentId
* @return Student
*/
Student findStudentsById(String studentId);
/**
* 根据学⽣姓名查询学⽣分数
* @param name
* @return 学⽣分数
*/
Double findGradeByName(String name);
}
查询:
...
@Autowired
private IgniteMapper igniteMapper;
...
Student student = igniteMapper.findStudentsById(studentId);
...
double grade = igniteMapper.findGradeByName(name);
注:由于ignite中可以⾃定义sql函数,测试过,在mybatis中ignite的⾃定义sql函数同样⽀持。
由于ignite中jdbc的⽅式属于轻客户端,所以性能要⽐api的⽅式差,⽽在通过mybatis查询的⽅式其性能表现通过测试得出的结果如下:在相同的sql相同数据的情况下,100并发查询:
mybatis查询
/findStudentsById 耗时 [13]ms.
广东省地税/findStudentsById 耗时 [9]ms.
/findStudentsById 耗时 [3]ms.
/findStudentsById 耗时 [10]ms.
/findStudentsById 耗时 [11]ms.
/findStudentsById 耗时 [11]ms.
/findStudentsById 耗时 [8]ms.
/findStudentsById 耗时 [14]ms.
/findStudentsById 耗时 [17]ms.
/findStudentsById 耗时 [11]ms.
/findStudentsById 耗时 [8]ms.
/findStudentsById 耗时 [13]ms.
/findStudentsById 耗时 [11]ms.
/findStudentsById 耗时 [10]ms.
/findStudentsById 耗时 [9]ms.
/findStudentsById 耗时 [10]ms.
中文核心期刊要目总览2012/findStudentsById 耗时 [12]ms.
/
findStudentsById 耗时 [9]ms.
/findStudentsById 耗时 [3]ms.
/findStudentsById 耗时 [3]ms.
...
/findStudentsById 耗时 [1]ms.
/findStudentsById 耗时 [2]ms.
/findStudentsById 耗时 [2]ms.
/findStudentsById 耗时 [2]ms.
/findStudentsById 耗时 [2]ms.
/findStudentsById 耗时 [2]ms.
/findStudentsById 耗时 [2]ms.
/
findStudentsById 耗时 [2]ms.
/findStudentsById 耗时 [1]ms.
/findStudentsById 耗时 [1]ms.
/findStudentsById 耗时 [1]ms.
/findStudentsById 耗时 [0]ms.
吞吐量为537/sec, 性能有波动情况,稳定后在2ms左右。api查询
/cpFindStudentsById 耗时 [0]ms.
/cpFindStudentsById 耗时 [0]ms.
/cpFindStudentsById 耗时 [0]ms.

本文发布于:2024-09-21 02:46:04,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/325837.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:查询   测试   缓存   性能   实例   基本
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议