CN104281592A - 一种基于视图的查询方法 - Google Patents

一种基于视图的查询方法 Download PDF

Info

Publication number
CN104281592A
CN104281592A CN201310278830.6A CN201310278830A CN104281592A CN 104281592 A CN104281592 A CN 104281592A CN 201310278830 A CN201310278830 A CN 201310278830A CN 104281592 A CN104281592 A CN 104281592A
Authority
CN
China
Prior art keywords
view
database table
identifier
major key
entity
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.)
Pending
Application number
CN201310278830.6A
Other languages
English (en)
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.)
China Unionpay Co Ltd
Original Assignee
China Unionpay 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 China Unionpay Co Ltd filed Critical China Unionpay Co Ltd
Priority to CN201310278830.6A priority Critical patent/CN104281592A/zh
Publication of CN104281592A publication Critical patent/CN104281592A/zh
Pending legal-status Critical Current

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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24553Query execution of query operations
    • 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/2453Query optimisation

Landscapes

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

Abstract

本发明公开一种基于视图的查询方法,包括以下步骤:基于多个数据库表生成视图,并且使得该视图包括包含标识符的列,所述标识符用于标识相应的数据库表,将标识符作为查询条件的部分,查询关于视图的特定的数据库表。

Description

一种基于视图的查询方法
技术领域
本发明涉及数据库查询优化,并且尤其涉及一种基于视图的查询方法。
背景技术
随着数据库数据的持续增加,通常通过拆分数据库表来摆脱单表访问的性能瓶颈。然而,随着数据库表数量的增加,创建的视图所涉及的数据库表也越来越多。因此,对于涉及多个数据库表的视图的查询性能较低。
需要一种优化的查询方法。
发明内容
根据本发明的一个目的,公开一种基于视图的查询方法,包括以下步骤:基于多个数据库表生成视图,并且使得该视图包括包含标识符的列,所述标识符用于标识相应的数据库表,将标识符作为查询条件的部分,查询关于视图的特定的数据库表。
优选地,上述方法还包括以下步骤:基于所述视图创建实体Bean,
将数据库表的标识符和数据库表的主键一起作为所述实体Bean的主键,利用所述实体Bean的主键对标识符所指示的数据库表执行查询。
本发明提高了基于视图的查询效率,尤其是基于视图的JPA主键查询效率,使基于视图的查询等效于基于单表的查询,使查询效率不再因为视图中增加表而受影响。
附图说明
在参照附图阅读了本发明的具体实施方式以后,本领域技术人员将会更清楚地了解本发明的各个方面。本领域技术人员应当理解的是,这些附图仅仅用于配合具体实施方式说明本发明的技术方案,而并非意在对本发明的保护范围构成限制。
图1是根据本发明实施例的基于视图的查询方法的步骤示意图。
图2是根据本发明实施例的基于视图的查询方法的示例。
具体实施方式
为了解决当涉及的数据库表的数量增加,基于视图的查询性能低下的问题,根据本发明提出在视图中新增数据库表的标识列,从而在查询条件中增加数据库的标识,指定要查询的特定的数据库表。图1是根据本发明实施例的基于视图的查询方法的步骤示意图。如图1所示,根据本发明的方法包括以下步骤:基于多个数据库表生成视图,并且使得该视图包括包含标识符的列,所述标识符用于标识相应的数据库表。以及,将标识符作为查询条件的部分,查询关于视图的特定的数据库表。
进一步,对于J2EE的环境,可以通过上述步骤并且在Entity Bean(实体Bean)中创建“伪主键”来提高JPA对视图的查询效率。
现有技术中,通过对视图创建Entity Bean,并将Entity Bean的主键指定为数据库表的主键,从而通过调用JPA主键查询接口执行查询。这种方法每次执行查询均需要访问视图中的每张表,当表套数增多,数据量增大时,该方法对视图中的表的无效查询(查询记录数是0)会严重降低查询性能。另一种方法是为每张表创建不同的Entity Bean,然后通过调用JPA主键查询接口实现单表主键查询。当表套数增多时创建的Entity Bean会越来越多,导致Entity Bean难以维护。
本发明进一步通过以下步骤来克服上述技术缺陷:基于所述视图创建实体Bean,将数据库表的标识符和数据库表的主键一起作为所述实体Bean的主键,利用所述实体Bean的主键对标识符所指示的数据库表执行查询。
示例
步骤1:在视图创建时,新增一列用于标识数据库表。例如:
对表tbl_his_log1和tbl_his_log2创建视图viw_his_log,
create view viw_his_log (identifier, ...) 
as
(select 1, t1.* from tbl_his_log1 t1) union all (select 2, t2.* from tbl_his_log2 t2)
通过上述步骤创建的视图包括了标识符(identifier)列,用于标识特定数据库表。
步骤2:基于视图创建Entity Bean,将Entity Bean的主键设置为是“identifier + 表的真实主键pri_key”。在查询的时候通过指定表的标识identifier 和表的真实主键pri_key,可以实现对特定的表执行主键查询,从而达到查询性能的提高。
图2是根据本发明实施例的基于视图的查询方法的示例。如图所示,在查询SQL语句中,指定查询条件为identifier=1, pri_key=2。数据库接收到查询SQL语句后,SQL解释器根据identifier=1做优化处理后,无需对视图的所有表执行查询,只需针对满足条件的表1执行查询。最后在表1上执行条件为pri_key=2的查询,并将结果返回。
通过以上实施方式的描述,本领域中的普通技术人员能够理解,在不偏离本发明的精神和范围的情况下,还可以对本发明的具体实施方式作各种变更和替换。这些变更和替换都落在本发明权利要求书所限定的范围内。

Claims (2)

1. 一种基于视图的查询方法,其特征在于,包括以下步骤:
基于多个数据库表生成视图,并且使得该视图包括包含标识符的列,所述标识符用于标识相应的数据库表,
将标识符作为查询条件的部分,查询关于视图的特定的数据库表。
2. 如权利要求1所述的方法,其特征在于,还包括以下步骤:
基于所述视图创建实体Bean,
将数据库表的标识符和数据库表的主键一起作为所述实体Bean的主键,
利用所述实体Bean的主键对标识符所指示的数据库表执行查询。
CN201310278830.6A 2013-07-04 2013-07-04 一种基于视图的查询方法 Pending CN104281592A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310278830.6A CN104281592A (zh) 2013-07-04 2013-07-04 一种基于视图的查询方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310278830.6A CN104281592A (zh) 2013-07-04 2013-07-04 一种基于视图的查询方法

Publications (1)

Publication Number Publication Date
CN104281592A true CN104281592A (zh) 2015-01-14

Family

ID=52256472

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310278830.6A Pending CN104281592A (zh) 2013-07-04 2013-07-04 一种基于视图的查询方法

Country Status (1)

Country Link
CN (1) CN104281592A (zh)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101127045A (zh) * 2007-09-25 2008-02-20 中兴通讯股份有限公司 数据库可重复读实现方法、装置及数据库管理系统
CN101158977A (zh) * 2007-11-21 2008-04-09 金蝶软件(中国)有限公司 一种对多业务单据数据的处理方法及系统
CN102243629A (zh) * 2010-05-12 2011-11-16 北京安华金和科技有限公司 一种基于多级视图和触发器的数据库透明加解密方法

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101127045A (zh) * 2007-09-25 2008-02-20 中兴通讯股份有限公司 数据库可重复读实现方法、装置及数据库管理系统
CN101158977A (zh) * 2007-11-21 2008-04-09 金蝶软件(中国)有限公司 一种对多业务单据数据的处理方法及系统
CN102243629A (zh) * 2010-05-12 2011-11-16 北京安华金和科技有限公司 一种基于多级视图和触发器的数据库透明加解密方法

Similar Documents

Publication Publication Date Title
KR101525529B1 (ko) 데이터 처리장치 및 그 데이터 매핑방법
US9703830B2 (en) Translation of a SPARQL query to a SQL query
JP6225261B2 (ja) データを記憶する方法及び装置
CN104714972B (zh) 数据库分表建立及查询方法
CN104573022A (zh) 一种HBase的数据查询方法及装置
CN111078702B (zh) 一种sql语句分类管理及统一查询方法和装置
CN105677683A (zh) 批量数据查询方法和装置
CN103488704A (zh) 一种数据存储方法及装置
CN104182405A (zh) 一种连接查询方法及装置
CN104361042A (zh) 一种信息检索方法及装置
CN103914483B (zh) 文件存储方法、装置及文件读取方法、装置
CN104268298A (zh) 一种创建数据库索引及其查询的方法
US20190188302A1 (en) Group-by-time operations with returned time context
CN104036007A (zh) 一种分布式数据库查询方法及装置
KR20200094074A (ko) 인덱스 관리 방법, 장치, 기기 및 저장 매체
CN104714974A (zh) 一种查询语句解析与再处理的方法和装置
KR20170067804A (ko) 라우팅 테이블의 유지 방법, 장치 및 저장매체
CN106055582A (zh) 一种替换数据库的表名的方法及装置
CN106933907B (zh) 数据表扩展指标的处理方法及装置
CN104636471A (zh) 一种程序代码的查找方法及装置
JP2013117873A (ja) データベース処理方法
Haque et al. Distributed RDF triple store using hbase and hive
US11263264B2 (en) Management of graphs using secondary index vertices
US11042578B2 (en) Multigram index for database query
CN104376055B (zh) 一种基于分片技术的大模型数据比较方法

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20150114