CN114237511A - 一种基于ShardingSphere-JDBC进行数据优化的解决方法 - Google Patents
一种基于ShardingSphere-JDBC进行数据优化的解决方法 Download PDFInfo
- Publication number
- CN114237511A CN114237511A CN202111553992.7A CN202111553992A CN114237511A CN 114237511 A CN114237511 A CN 114237511A CN 202111553992 A CN202111553992 A CN 202111553992A CN 114237511 A CN114237511 A CN 114237511A
- Authority
- CN
- China
- Prior art keywords
- sql
- target
- query
- data
- jdbc
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 9
- 238000012217 deletion Methods 0.000 claims abstract description 6
- 230000037430 deletion Effects 0.000 claims abstract description 6
- 238000013507 mapping Methods 0.000 claims description 6
- 238000005457 optimization Methods 0.000 claims 3
- 230000004075 alteration Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
- G06F16/24553—Query execution of query operations
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input 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/06—Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
- G06F3/0601—Interfaces specially adapted for storage systems
- G06F3/0628—Interfaces specially adapted for storage systems making use of a particular technique
- G06F3/0646—Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
- G06F3/0652—Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
-
- Y—GENERAL 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
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE 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/00—Energy 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进行数据优化的解决方法。
背景技术
随着单库单表中的数据量越来越大、数据库的查询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 (4)
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 模板中的参数来遍历目标库目标表中的数据。
2.根据权利要求1所述的一种基于ShardingSphere-JDBC进行数据优化的解决方法,其特征在于:根据查询sql查询结果shardingColumn,替换路由规则sql模板中的参数。
3.根据权利要求2所述的一种基于ShardingSphere-JDBC进行数据优化的解决方法,其特征在于:利用ShardingRoutDecorate类来解析刚才生成的路由规则sql,获取该sql的路由结果,判断该sql的路由规则是否包含目标库目标表,如果不包含目标库目标表则通过table,shardingColumn与查询sql结果替换删除sql模板中参数生成删除sql,执行删除sql来进行数据删除。
4.根据权利要求3所述的一种基于ShardingSphere-JDBC进行数据优化的解决方法,其特征在于:删除后根据查询sql返回的数据数量更新limit参数,重新根据查询sql模板生成查询sql继续遍历目标库目标表数据,直到遍历完成,程序结束。
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 true CN114237511A (zh) | 2022-03-25 |
CN114237511B 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 (5)
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 | 东软集团股份有限公司 | 增量数据查询方法及装置、存储介质、电子设备 |
US20180137184A1 (en) * | 2016-11-15 | 2018-05-17 | Spirent Communications, Inc. | Sql interceptor for use with third party data analytics packages |
CN113127568A (zh) * | 2021-05-11 | 2021-07-16 | 中国电信股份有限公司江西分公司 | 一种分布式内存数据库数据路由和分库分表的方法及装置 |
-
2021
- 2021-12-18 CN CN202111553992.7A patent/CN114237511B/zh active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20180137184A1 (en) * | 2016-11-15 | 2018-05-17 | Spirent Communications, Inc. | Sql interceptor for use with third party data analytics packages |
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)
Title |
---|
林志鹏 等: "基于Sharding-JDBC 的海量北斗数据存储方案", 《电气开关》, no. 1, pages 39 - 48 * |
Also Published As
Publication number | Publication date |
---|---|
CN114237511B (zh) | 2024-01-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10671642B2 (en) | Copying data changes to a target database | |
CN108369587B (zh) | 创建用于交换的表 | |
CN108572996B (zh) | 数据库表结构的同步方法、装置、电子设备和存储介质 | |
US8396852B2 (en) | Evaluating execution plan changes after a wakeup threshold time | |
US8924373B2 (en) | Query plans with parameter markers in place of object identifiers | |
TWI549009B (zh) | 資料庫管理方法、資料庫管理系統,以及資料庫樹狀結構 | |
JP2022500727A (ja) | データベースにおけるツームストーンレコードの早期除去のためのシステムおよび方法 | |
CN113204571B (zh) | 涉及写入操作的sql执行方法、装置及存储介质 | |
CN112912870A (zh) | 租户标识符的转换 | |
US20240289386A1 (en) | Graph data management | |
US8396858B2 (en) | Adding entries to an index based on use of the index | |
CN111984625B (zh) | 数据库负载特征处理方法、装置、介质和电子设备 | |
WO2024078122A1 (zh) | 数据库表扫描的方法、装置以及设备 | |
Kvet et al. | Master index access as a data tuple and block locator | |
CN117235028A (zh) | 一种基于日志文件的数据查询方法和装置 | |
US10747438B1 (en) | Reporting using archived data | |
WO2024159575A1 (zh) | 数据处理方法、装置、电子设备及存储介质 | |
WO2015015559A1 (ja) | 検索システムおよび検索方法 | |
CN114237511A (zh) | 一种基于ShardingSphere-JDBC进行数据优化的解决方法 | |
CN112889039A (zh) | 用于克隆后租户标识符转换的记录的标识 | |
CN115374121A (zh) | 数据库索引的生成方法、机器可读存储介质与计算机设备 | |
CN115391346A (zh) | 数据库聚合索引的生成方法、存储介质与计算机设备 | |
CN110413617B (zh) | 一种根据数据量的大小动态调节哈希表组的方法 | |
CN114461675A (zh) | 基于kv存储的部分索引实现方法及系统 | |
CN114443625A (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 |