CN114237511B - 一种基于ShardingSphere-JDBC进行数据优化的解决方法 - Google Patents

一种基于ShardingSphere-JDBC进行数据优化的解决方法 Download PDF

Info

Publication number
CN114237511B
CN114237511B CN202111553992.7A CN202111553992A CN114237511B CN 114237511 B CN114237511 B CN 114237511B CN 202111553992 A CN202111553992 A CN 202111553992A CN 114237511 B CN114237511 B CN 114237511B
Authority
CN
China
Prior art keywords
sql
query
data
class
parameters
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111553992.7A
Other languages
English (en)
Other versions
CN114237511A (zh
Inventor
郭成强
张彪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Shidong Technology Co ltd
Original Assignee
Hangzhou Shidong Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Shidong Technology Co ltd filed Critical Hangzhou Shidong Technology Co ltd
Priority to CN202111553992.7A priority Critical patent/CN114237511B/zh
Publication of CN114237511A publication Critical patent/CN114237511A/zh
Application granted granted Critical
Publication of CN114237511B publication Critical patent/CN114237511B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24553Query execution of query operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0646Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
    • G06F3/0652Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Human Computer Interaction (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种基于ShardingSphere‑JDBC进行数据优化的解决方法,包括以下步骤:根据查询sql查询结果shardingColumn,替换路由规则sql模板中的参数,利用ShardingRoutDecorate类来解析刚才生成的路由规则sql,获取该sql的路由结果,判断该sql的路由规则是否包含目标库目标表,如果不包含目标库目标表则通过table,shardingColumn与查询sql结果替换删除sql模板中参数生成删除sql,执行删除sql来进行数据删除,删除后根据查询sql返回的数据数量更新limit参数,重新根据查询sql模板生成查询sql继续遍历目标库目标表数据,直到遍历完成,程序结束。本发明降低手动删除表数据造成的数据丢失几率;减少二次配置,原有配置拿来即用;删除冗余数据,释放更多的硬盘空间。

Description

一种基于ShardingSphere-JDBC进行数据优化的解决方法
技术领域
本发明涉及计算机软件技术领域,具体为一种基于ShardingSphere-JDBC进行数据优化的解决方法。
背景技术
随着单库单表中的数据量越来越大、数据库的查询QPS越来越高,一般采用分库分表的方法来应对出现的问题,在上线分库分表时,通常会对数据进行冗余处理操作保证数据正常,本方案是为了解决此操作带来的数据冗余问题。
发明内容
本发明的目的在于提供一种基于ShardingSphere-JDBC进行数据优化的解决方法,以解决上述背景技术中提出的问题。
为实现上述目的,本发明提供如下技术方案:一种基于ShardingSphere-JDBC进行数据优化的解决方法,包括以下步骤:
启动程序之前,先对sharding-jdbc分库分表规则进行配置,需配置:
spring.shardingsphere.datasource参数;
spring.shardingsphere.sharding.tables参数;
spring.shardingsphere.sharding.binding-tables参数;
配置完分库分表规则后再配置目标库目标表参数,如下primaryKey,shardingColumn,table,limit;
启动服务后,服务会自动读取配置,利用注解自动注入shardingDataSource类;
获取shardingDataSource类中ShardingRuntimeContext类,再从ShardingRuntimeContext中获取ShardingRule,ShardingSphereMeteDate与SQLParserEngine类,利用这些类作为参数生成ShardingRoutDecorate类;
程序会根据目标库目标表参数shardingColumn,table, primaryKey,limit替换查询sql 模板中的参数来遍历目标库目标表中的数据。
优选的,根据查询sql查询结果shardingColumn,替换路由规则sql模板中的参数。
优选的,利用ShardingRoutDecorate类来解析刚才生成的路由规则sql,获取该sql的路由结果,判断该sql的路由规则是否包含目标库目标表,如果不包含目标库目标表则通过table,shardingColumn与查询sql结果替换删除sql模板中参数生成删除sql,执行删除sql来进行数据删除。
优选的,删除后根据查询sql返回的数据数量更新limit参数,重新根据查询sql模板生成查询sql继续遍历目标库目标表数据,直到遍历完成,程序结束。
本发明提出的一种基于ShardingSphere-JDBC进行数据优化的解决方法,有益效果在于:
1.本发明降低手动删除表数据造成的数据丢失几率;
2.本发明减少二次配置,原有配置拿来即用;
3.本发明删除冗余数据,释放更多的硬盘空间。
附图说明
图1为本发明的流程图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
实施例1,请参阅图1本发明提供一种技术方案:一种基于ShardingSphere-JDBC进行数据优化的解决方法,其特征在于,包括以下步骤:
启动程序之前,先对sharding-jdbc分库分表规则进行配置,需配置:
spring.shardingsphere.datasource参数;
spring.shardingsphere.sharding.tables参数;
spring.shardingsphere.sharding.binding-tables参数;
配置完分库分表规则后再配置目标库目标表参数,如下primaryKey,shardingColumn,table,limit;
启动服务后,服务会自动读取配置,利用注解自动注入shardingDataSource类;
获取shardingDataSource类中ShardingRuntimeContext类,再从ShardingRuntimeContext中获取ShardingRule,ShardingSphereMeteDate与SQLParserEngine类,利用这些类作为参数生成ShardingRoutDecorate类;
程序会根据目标库目标表参数shardingColumn,table, primaryKey,limit替换查询sql 模板中的参数来遍历目标库目标表中的数据;
根据查询sql查询结果shardingColumn,替换路由规则sql模板中的参数,利用ShardingRoutDecorate类来解析刚才生成的路由规则sql,获取该sql的路由结果,判断该sql的路由规则是否包含目标库目标表,如果不包含目标库目标表则通过table,shardingColumn与查询sql结果替换删除sql模板中参数生成删除sql,执行删除sql来进行数据删除,删除后根据查询sql返回的数据数量更新limit参数,重新根据查询sql模板生成查询sql继续遍历目标库目标表数据,直到遍历完成,程序结束。
尽管已经示出和描述了本发明的实施例,对于本领域的普通技术人员而言,可以理解在不脱离本发明的原理和精神的情况下可以对这些实施例进行多种变化、修改、替换和变型,本发明的范围由所附权利要求及其等同物限定。

Claims (1)

1.一种基于ShardingSphere-JDBC进行数据优化的解决方法,其特征在于,包括以下步骤:
启动程序之前,先对sharding-jdbc分库分表规则进行配置,需配置:
spring.shardingsphere.datasource参数;
spring.shardingsphere.sharding.tables参数;
spring.shardingsphere.sharding.binding-tables参数;
配置完分库分表规则后再配置目标库目标表参数,如下primaryKey,shardingColumn,table,limit;
启动服务后,服务会自动读取配置,利用注解自动注入shardingDataSource类;
获取shardingDataSource类中ShardingRuntimeContext类,再从ShardingRuntimeContext中获取ShardingRule,ShardingSphereMeteDate与SQLParserEngine类,利用这些类作为参数生成ShardingRoutDecorate类;
程序会根据目标库目标表参数shardingColumn,table, primaryKey,limit替换查询sql 模板中的参数来遍历目标库目标表中的数据;
根据查询sql查询结果shardingColumn,替换路由规则sql模板中的参数;
利用ShardingRoutDecorate类来解析刚才生成的路由规则sql,获取该sql的路由结果,判断该sql的路由规则是否包含目标库目标表,如果不包含目标库目标表则通过table,shardingColumn与查询sql结果替换删除sql模板中参数生成删除sql,执行删除sql来进行数据删除;
删除后根据查询sql返回的数据数量更新limit参数,重新根据查询sql模板生成查询sql继续遍历目标库目标表数据,直到遍历完成,程序结束。
CN202111553992.7A 2021-12-18 2021-12-18 一种基于ShardingSphere-JDBC进行数据优化的解决方法 Active CN114237511B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111553992.7A CN114237511B (zh) 2021-12-18 2021-12-18 一种基于ShardingSphere-JDBC进行数据优化的解决方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111553992.7A CN114237511B (zh) 2021-12-18 2021-12-18 一种基于ShardingSphere-JDBC进行数据优化的解决方法

Publications (2)

Publication Number Publication Date
CN114237511A CN114237511A (zh) 2022-03-25
CN114237511B true CN114237511B (zh) 2024-01-26

Family

ID=80758302

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111553992.7A Active CN114237511B (zh) 2021-12-18 2021-12-18 一种基于ShardingSphere-JDBC进行数据优化的解决方法

Country Status (1)

Country Link
CN (1) CN114237511B (zh)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107423390A (zh) * 2017-07-21 2017-12-01 上海德拓信息技术股份有限公司 一种基于oltp‑olap混合关系型数据库系统内部的数据实时同步算法
CN107480262A (zh) * 2017-08-05 2017-12-15 中山大学 一种基于网页的数据库通用管理系统
CN108009207A (zh) * 2017-11-06 2018-05-08 东软集团股份有限公司 增量数据查询方法及装置、存储介质、电子设备
CN113127568A (zh) * 2021-05-11 2021-07-16 中国电信股份有限公司江西分公司 一种分布式内存数据库数据路由和分库分表的方法及装置

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10380139B2 (en) * 2016-11-15 2019-08-13 Spirent Communications, Inc. SQL interceptor for use with third party data analytics packages

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107423390A (zh) * 2017-07-21 2017-12-01 上海德拓信息技术股份有限公司 一种基于oltp‑olap混合关系型数据库系统内部的数据实时同步算法
CN107480262A (zh) * 2017-08-05 2017-12-15 中山大学 一种基于网页的数据库通用管理系统
CN108009207A (zh) * 2017-11-06 2018-05-08 东软集团股份有限公司 增量数据查询方法及装置、存储介质、电子设备
CN113127568A (zh) * 2021-05-11 2021-07-16 中国电信股份有限公司江西分公司 一种分布式内存数据库数据路由和分库分表的方法及装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于Sharding-JDBC 的海量北斗数据存储方案;林志鹏 等;《电气开关》(第1期);39-48 *

Also Published As

Publication number Publication date
CN114237511A (zh) 2022-03-25

Similar Documents

Publication Publication Date Title
CN105260403B (zh) 通用跨数据库访问方法
US20230376506A1 (en) System and Method for Analysis and Management of Data Distribution in a Distributed Database Environment
US8396852B2 (en) Evaluating execution plan changes after a wakeup threshold time
US8924373B2 (en) Query plans with parameter markers in place of object identifiers
US9679021B2 (en) Parallel transactional-statistics collection for improving operation of a DBMS optimizer module
CN111708804B (zh) 数据处理方法、装置、设备及介质
CN106156088B (zh) 一种索引数据处理方法、数据查询方法及装置
EP2772879A1 (en) Correlating data from multiple business processes to a business process scenario
CN111737355B (zh) 基于MongoDB元数据管理的异构数据源同步的方法及系统
CN104615710A (zh) 一种电子地图框架数据更新方法
CN110837515A (zh) 一种基于数据库的数据处理方法及电子设备
CN109885585B (zh) 支持存储过程、触发器与视图的分布式数据库系统和方法
CN108062314B (zh) 动态分表数据处理方法和装置
US11537613B1 (en) Merge small file consolidation
CN104536987A (zh) 一种查询数据的方法及装置
CN113886395A (zh) 基于openGauss平台的高速数据导入导出方法
KR20190063835A (ko) 인-메모리 데이터베이스의 실시간 데이터 변경 처리 시스템
CN112506964A (zh) 数据查询方法、系统及计算机可读存储介质
CN113204571A (zh) 涉及写入操作的sql执行方法、装置及存储介质
CN110795431B (zh) 环境监测数据处理方法、装置、设备及存储介质
US8396858B2 (en) Adding entries to an index based on use of the index
CN115438122A (zh) 数据异构同步系统
CN103365987A (zh) 一种基于共享磁盘架构的集群数据库系统及数据处理方法
CN114237511B (zh) 一种基于ShardingSphere-JDBC进行数据优化的解决方法
CN109165262A (zh) 一种关系型大表的分片集群系统及其分片方法

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant