简体   繁体   English

java.sql.date,java.sql.timestamp谓词-> Oracle分区数据类型

[英]java.sql.date , java.sql.timestamp predicate -> Oracle partition data type

Hi we had big Oracle column object and we had partitioned it with a Data Type of DATE 嗨,我们有一个很大的Oracle列对象,并用DATE数据类型对其进行了分区

One of the partitions looks like this : 其中一个分区看起来像这样:

GCP_P1  TO_DATE(' 2011-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN') 83  M_DATA01    DISABLED    348132  15214   146 08.06.2014 02:20:40 1078    0

Each partition is one week long. 每个分区为期一周。

We run our sql's through thin client with jdbc. 我们使用jdbc通过瘦客户端运行sql。 No ORM just pure jdbc. 没有ORM只是纯jdbc。

When our predicate item for the partitioned column is java.sql.timestamp we realized that the query does not benefit from partition. 当我们用于分区列的谓词项是java.sql.timestamp时,我们意识到查询不会从分区中受益。 However when it is of type java.sql.date the execution plan shows a successful partition access. 但是,当类型为java.sql.date时,执行计划将显示成功的分区访问。

So for example our sql looks like this : 因此,例如我们的sql看起来像这样:

SELECT COUNT(1) FROM ATABLE WHERE PARTITIONED_COLUMN > ?

When our java statement is : 当我们的java语句是:

preparedStatement.setDate(...); // it benefits from partition

But when it is like this : 但是当这样的时候:

preparedStatement.setTimestamp(...); //it does not benefits from partition

I am looking them from Toad. 我正在从蟾蜍那里看它们。 I have experienced that when it is java.sql.date, It is interpreted as DATE on oracle, when it is java.sql.timestamp it is interpreted as TIMESTAMP 我经历过,当它是java.sql.date时,它在oracle上被解释为DATE,当它是java.sql.timestamp时,它被解释为TIMESTAMP

I am following the captured jdbc date type with the following sql statement 我正在使用以下SQL语句跟踪捕获的JDBC日期类型

SELECT *
  FROM V$SQL_BIND_CAPTURE
WHERE WAS_CAPTURED = 'YES' AND LAST_CAPTURED BETWEEN SYSDATE-1/50 AND SYSDATE
ORDER BY LAST_CAPTURED DESC;

My question is have you experienced such an issue? 我的问题是您遇到过这样的问题吗? If so would you direct me to some documents. 如果是这样,您可以指导我处理一些文件。

The case you describe is documented section 8 - Mapping SQL and Java Types of "Getting Started with the JDBC API" 您描述的案例记录在第8节“映射JDBC API入门”的 SQL和Java类型中

8.3.12 DATE, TIME, and TIMESTAMP 8.3.12日期,时间和时间戳

Because the standard Java class java.util.Date does not match any of these three JDBC date/time types exactly (it includes both DATE and TIME information but has no nanoseconds), JDBC defines three subclasses of java.util.Date to correspond to the SQL types. 因为标准Java类java.util.Date与这三种JDBC日期/时间类型中的任何一种都不完全匹配(它既包含DATE和TIME信息,又没有纳秒),所以JDBC定义了java.util.Date的三个子类来对应SQL类型。 They are: 他们是:

java.sql.Date java.sql.Date

for SQL DATE information. 有关SQL DATE的信息。 The hour, minute, second, and millisecond fields of the java.util.Date base class should be set to zero. java.util.Date基类的小时,分​​钟,秒和毫秒字段应设置为零。 If the number of milliseconds supplied to the java.sql.Date constructor is negative, the driver will compute the date as the number of milliseconds before January 1, 1970. Otherwise, the date is computed as the specified number of milliseconds after January 1, 1970. 如果提供给java.sql.Date构造函数的毫秒数为负,则驱动程序将日期计算为1970年1月1日之前的毫秒数。否则,日期将计算为1月1日之后的指定毫秒数。 1970年。

java.sql.Time 的java.sql.Time

for SQL TIME information. SQL TIME信息。 The year, month, and day fields of the java.util.Date base class are set to 1970, January, and 1. This is the "zero" date in the Java epoch. java.util.Date基类的年,月和日字段设置为1970,一月和1。这是Java时代中的“零”日期。

java.sql.Timestamp 的java.sql.Timestamp

for SQL TIMESTAMP information. 有关SQL TIMESTAMP的信息。 This class extends java.util.Date by adding a nanoseconds field. 此类通过添加一个nanoseconds字段来扩展java.util.Date。

The oracle jdbc developers guide contains the mapping from jdbc types to oracle data types. oracle jdbc开发人员指南包含从jdbc类型到oracle数据类型的映射。 There is a section specific to the DATE data type due to its complexity. 由于其复杂性,有一部分专门针对DATE数据类型。 It has the following note: 它具有以下注意事项:

In Oracle Database 11g, if you have an index on a DATE column to be used by a SQL query, then to obtain faster and accurate results, you must use the setObject method in the following way: 在Oracle数据库11g中,如果在DATE列上有一个索引供SQL查询使用,则为了获得更快,更准确的结果,必须按以下方式使用setObject方法:

 Date d = parseIsoDate(val); 
 Timestamp t = new Timestamp(d.getTime());
 stmt.setObject(pos, new oracle.sql.DATE(t,(Calendar)UTC_CAL.clone()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM