Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8fbe0e15
提交
8fbe0e15
authored
5月 28, 2017
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
# Conflicts: # h2/src/docsrc/html/changelog.html
上级
018fad1f
8582753e
显示空白字符变更
内嵌
并排
正在显示
28 个修改的文件
包含
518 行增加
和
43 行删除
+518
-43
help.csv
h2/src/docsrc/help/help.csv
+4
-2
changelog.html
h2/src/docsrc/html/changelog.html
+8
-0
MANIFEST.MF
h2/src/main/META-INF/MANIFEST.MF
+1
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+39
-0
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+15
-3
CreateIndex.java
h2/src/main/org/h2/command/ddl/CreateIndex.java
+7
-1
CreateTableData.java
h2/src/main/org/h2/command/ddl/CreateTableData.java
+0
-1
Mode.java
h2/src/main/org/h2/engine/Mode.java
+11
-0
Session.java
h2/src/main/org/h2/engine/Session.java
+21
-1
Function.java
h2/src/main/org/h2/expression/Function.java
+5
-1
IndexType.java
h2/src/main/org/h2/index/IndexType.java
+20
-1
TraceSystem.java
h2/src/main/org/h2/message/TraceSystem.java
+3
-0
WriteBuffer.java
h2/src/main/org/h2/mvstore/WriteBuffer.java
+1
-1
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+1
-3
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+6
-2
help.csv
h2/src/main/org/h2/res/help.csv
+2
-2
JoinBatch.java
h2/src/main/org/h2/table/JoinBatch.java
+3
-0
LinkSchema.java
h2/src/main/org/h2/table/LinkSchema.java
+6
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+6
-2
RegularTable.java
h2/src/main/org/h2/table/RegularTable.java
+1
-4
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+2
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+23
-0
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+23
-0
TestQueryCache.java
h2/src/test/org/h2/test/db/TestQueryCache.java
+24
-9
TestTableEngines.java
h2/src/test/org/h2/test/db/TestTableEngines.java
+159
-7
TestMvccMultiThreaded2.java
h2/src/test/org/h2/test/mvcc/TestMvccMultiThreaded2.java
+118
-0
TestTraceSystem.java
h2/src/test/org/h2/test/unit/TestTraceSystem.java
+7
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
8fbe0e15
...
@@ -415,9 +415,11 @@ ALTER VIEW ADDRESS_VIEW RECOMPILE
...
@@ -415,9 +415,11 @@ ALTER VIEW ADDRESS_VIEW RECOMPILE
"
"
"Commands (DDL)","ANALYZE","
"Commands (DDL)","ANALYZE","
ANALYZE [ SAMPLE_SIZE rowCountInt ]
ANALYZE [
TABLE tableName ] [
SAMPLE_SIZE rowCountInt ]
","
","
Updates the selectivity statistics of all tables. The selectivity is used by the
Updates the selectivity statistics of tables.
If no table name is given, all tables are analyzed.
The selectivity is used by the
cost based optimizer to select the best index for a given query. If no sample
cost based optimizer to select the best index for a given query. If no sample
size is set, up to 10000 rows per table are read. The value 0 means all rows are
size is set, up to 10000 rows per table are read. The value 0 means all rows are
read. The selectivity can be set manually using ALTER TABLE ALTER COLUMN
read. The selectivity can be set manually using ALTER TABLE ALTER COLUMN
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
8fbe0e15
...
@@ -23,6 +23,14 @@ Change Log
...
@@ -23,6 +23,14 @@ Change Log
<ul>
<ul>
<li>
Fix startup issue when using "CHECK" as a column name.
<li>
Fix startup issue when using "CHECK" as a column name.
</li>
</li>
<li>
Issue #423: ANALYZE performed multiple times on one table during execution of the same statement.
</li>
<li>
Issue #426: Support ANALYZE TABLE statement
</li>
<li>
Issue #438: Fix slow logging via SLF4J (TRACE_LEVEL_FILE=4).
</li>
<li>
Issue #472: Support CREATE SEQUENCE ... ORDER as a NOOP for Oracle compatibility
</li>
</ul>
</ul>
<h2>
Version 1.4.195 (2017-04-23)
</h2>
<h2>
Version 1.4.195 (2017-04-23)
</h2>
...
...
h2/src/main/META-INF/MANIFEST.MF
浏览文件 @
8fbe0e15
...
@@ -58,4 +58,5 @@ Export-Package: org.h2;version="${version}",
...
@@ -58,4 +58,5 @@ Export-Package: org.h2;version="${version}",
org.h2.mvstore.db;version="${version}",
org.h2.mvstore.db;version="${version}",
org.h2.mvstore.type;version="${version}",
org.h2.mvstore.type;version="${version}",
org.h2.mvstore.rtree;version="${version}"
org.h2.mvstore.rtree;version="${version}"
Provide-Capability: osgi.service;objectClass:List<String>=org.osgi.service.jdbc.DataSourceFactory
Premain-Class: org.h2.util.Profiler
Premain-Class: org.h2.util.Profiler
h2/src/main/org/h2/command/Parser.java
浏览文件 @
8fbe0e15
...
@@ -550,6 +550,11 @@ public class Parser {
...
@@ -550,6 +550,11 @@ public class Parser {
private
Prepared
parseAnalyze
()
{
private
Prepared
parseAnalyze
()
{
Analyze
command
=
new
Analyze
(
session
);
Analyze
command
=
new
Analyze
(
session
);
if
(
readIf
(
"TABLE"
))
{
Table
table
=
readTableOrView
();
command
.
setTable
(
table
);
command
.
setTop
(
readPositiveInt
());
}
if
(
readIf
(
"SAMPLE_SIZE"
))
{
if
(
readIf
(
"SAMPLE_SIZE"
))
{
command
.
setTop
(
readPositiveInt
());
command
.
setTop
(
readPositiveInt
());
}
}
...
@@ -4660,6 +4665,8 @@ public class Parser {
...
@@ -4660,6 +4665,8 @@ public class Parser {
command
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
command
.
setCacheSize
(
ValueExpression
.
get
(
ValueLong
.
get
(
1
)));
}
else
if
(
readIf
(
"BELONGS_TO_TABLE"
))
{
}
else
if
(
readIf
(
"BELONGS_TO_TABLE"
))
{
command
.
setBelongsToTable
(
true
);
command
.
setBelongsToTable
(
true
);
}
else
if
(
readIf
(
"ORDER"
))
{
// Oracle compatibility
}
else
{
}
else
{
break
;
break
;
}
}
...
@@ -4676,6 +4683,10 @@ public class Parser {
...
@@ -4676,6 +4683,10 @@ public class Parser {
return
false
;
return
false
;
}
}
private
boolean
readIfAffinity
()
{
return
readIf
(
"AFFINITY"
)
||
readIf
(
"SHARD"
);
}
private
CreateConstant
parseCreateConstant
()
{
private
CreateConstant
parseCreateConstant
()
{
boolean
ifNotExists
=
readIfNotExists
();
boolean
ifNotExists
=
readIfNotExists
();
String
constantName
=
readIdentifierWithSchema
();
String
constantName
=
readIdentifierWithSchema
();
...
@@ -5900,6 +5911,7 @@ public class Parser {
...
@@ -5900,6 +5911,7 @@ public class Parser {
String
constraintName
=
null
,
comment
=
null
;
String
constraintName
=
null
,
comment
=
null
;
boolean
ifNotExists
=
false
;
boolean
ifNotExists
=
false
;
boolean
allowIndexDefinition
=
database
.
getMode
().
indexDefinitionInCreateTable
;
boolean
allowIndexDefinition
=
database
.
getMode
().
indexDefinitionInCreateTable
;
boolean
allowAffinityKey
=
database
.
getMode
().
allowAffinityKey
;
if
(
readIf
(
"CONSTRAINT"
))
{
if
(
readIf
(
"CONSTRAINT"
))
{
ifNotExists
=
readIfNotExists
();
ifNotExists
=
readIfNotExists
();
constraintName
=
readIdentifierWithSchema
(
schema
.
getName
());
constraintName
=
readIdentifierWithSchema
(
schema
.
getName
());
...
@@ -5951,6 +5963,12 @@ public class Parser {
...
@@ -5951,6 +5963,12 @@ public class Parser {
read
(
"BTREE"
);
read
(
"BTREE"
);
}
}
return
command
;
return
command
;
}
else
if
(
allowAffinityKey
&&
readIfAffinity
())
{
read
(
"KEY"
);
read
(
"("
);
CreateIndex
command
=
createAffinityIndex
(
schema
,
tableName
,
parseIndexColumnList
());
command
.
setIfTableExists
(
ifTableExists
);
return
command
;
}
}
AlterTableAddConstraint
command
;
AlterTableAddConstraint
command
;
if
(
readIf
(
"CHECK"
))
{
if
(
readIf
(
"CHECK"
))
{
...
@@ -6118,6 +6136,9 @@ public class Parser {
...
@@ -6118,6 +6136,9 @@ public class Parser {
if
(
readIf
(
"CONSTRAINT"
))
{
if
(
readIf
(
"CONSTRAINT"
))
{
constraintName
=
readColumnIdentifier
();
constraintName
=
readColumnIdentifier
();
}
}
// For compatibility with Apache Ignite.
boolean
allowAffinityKey
=
database
.
getMode
().
allowAffinityKey
;
boolean
affinity
=
allowAffinityKey
&&
readIfAffinity
();
if
(
readIf
(
"PRIMARY"
))
{
if
(
readIf
(
"PRIMARY"
))
{
read
(
"KEY"
);
read
(
"KEY"
);
boolean
hash
=
readIf
(
"HASH"
);
boolean
hash
=
readIf
(
"HASH"
);
...
@@ -6133,6 +6154,16 @@ public class Parser {
...
@@ -6133,6 +6154,16 @@ public class Parser {
if
(
readIf
(
"AUTO_INCREMENT"
))
{
if
(
readIf
(
"AUTO_INCREMENT"
))
{
parseAutoIncrement
(
column
);
parseAutoIncrement
(
column
);
}
}
if
(
affinity
)
{
CreateIndex
idx
=
createAffinityIndex
(
schema
,
tableName
,
cols
);
command
.
addConstraintCommand
(
idx
);
}
}
else
if
(
affinity
)
{
read
(
"KEY"
);
IndexColumn
[]
cols
=
{
new
IndexColumn
()
};
cols
[
0
].
columnName
=
column
.
getName
();
CreateIndex
idx
=
createAffinityIndex
(
schema
,
tableName
,
cols
);
command
.
addConstraintCommand
(
idx
);
}
else
if
(
readIf
(
"UNIQUE"
))
{
}
else
if
(
readIf
(
"UNIQUE"
))
{
AlterTableAddConstraint
unique
=
new
AlterTableAddConstraint
(
AlterTableAddConstraint
unique
=
new
AlterTableAddConstraint
(
session
,
schema
,
false
);
session
,
schema
,
false
);
...
@@ -6251,6 +6282,14 @@ public class Parser {
...
@@ -6251,6 +6282,14 @@ public class Parser {
return
command
;
return
command
;
}
}
private
CreateIndex
createAffinityIndex
(
Schema
schema
,
String
tableName
,
IndexColumn
[]
indexColumns
)
{
CreateIndex
idx
=
new
CreateIndex
(
session
,
schema
);
idx
.
setTableName
(
tableName
);
idx
.
setIndexColumns
(
indexColumns
);
idx
.
setAffinity
(
true
);
return
idx
;
}
private
static
int
getCompareType
(
int
tokenType
)
{
private
static
int
getCompareType
(
int
tokenType
)
{
switch
(
tokenType
)
{
switch
(
tokenType
)
{
case
EQUAL:
case
EQUAL:
...
...
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
8fbe0e15
...
@@ -22,8 +22,8 @@ import org.h2.value.ValueInt;
...
@@ -22,8 +22,8 @@ import org.h2.value.ValueInt;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
/**
/**
* This class represents the statement
* This class represents the statement
s
* ANALYZE
* ANALYZE
and ANALYZE TABLE
*/
*/
public
class
Analyze
extends
DefineCommand
{
public
class
Analyze
extends
DefineCommand
{
...
@@ -31,20 +31,32 @@ public class Analyze extends DefineCommand {
...
@@ -31,20 +31,32 @@ public class Analyze extends DefineCommand {
* The sample size.
* The sample size.
*/
*/
private
int
sampleRows
;
private
int
sampleRows
;
/**
* used in ANALYZE TABLE...
*/
private
Table
table
;
public
Analyze
(
Session
session
)
{
public
Analyze
(
Session
session
)
{
super
(
session
);
super
(
session
);
sampleRows
=
session
.
getDatabase
().
getSettings
().
analyzeSample
;
sampleRows
=
session
.
getDatabase
().
getSettings
().
analyzeSample
;
}
}
public
void
setTable
(
Table
table
)
{
this
.
table
=
table
;
}
@Override
@Override
public
int
update
()
{
public
int
update
()
{
session
.
commit
(
true
);
session
.
commit
(
true
);
session
.
getUser
().
checkAdmin
();
session
.
getUser
().
checkAdmin
();
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
if
(
table
!=
null
)
{
analyzeTable
(
session
,
table
,
sampleRows
,
true
);
}
else
{
for
(
Table
table
:
db
.
getAllTablesAndViews
(
false
))
{
for
(
Table
table
:
db
.
getAllTablesAndViews
(
false
))
{
analyzeTable
(
session
,
table
,
sampleRows
,
true
);
analyzeTable
(
session
,
table
,
sampleRows
,
true
);
}
}
}
return
0
;
return
0
;
}
}
...
...
h2/src/main/org/h2/command/ddl/CreateIndex.java
浏览文件 @
8fbe0e15
...
@@ -26,7 +26,7 @@ public class CreateIndex extends SchemaCommand {
...
@@ -26,7 +26,7 @@ public class CreateIndex extends SchemaCommand {
private
String
tableName
;
private
String
tableName
;
private
String
indexName
;
private
String
indexName
;
private
IndexColumn
[]
indexColumns
;
private
IndexColumn
[]
indexColumns
;
private
boolean
primaryKey
,
unique
,
hash
,
spatial
;
private
boolean
primaryKey
,
unique
,
hash
,
spatial
,
affinity
;
private
boolean
ifTableExists
;
private
boolean
ifTableExists
;
private
boolean
ifNotExists
;
private
boolean
ifNotExists
;
private
String
comment
;
private
String
comment
;
...
@@ -98,6 +98,8 @@ public class CreateIndex extends SchemaCommand {
...
@@ -98,6 +98,8 @@ public class CreateIndex extends SchemaCommand {
indexType
=
IndexType
.
createPrimaryKey
(
persistent
,
hash
);
indexType
=
IndexType
.
createPrimaryKey
(
persistent
,
hash
);
}
else
if
(
unique
)
{
}
else
if
(
unique
)
{
indexType
=
IndexType
.
createUnique
(
persistent
,
hash
);
indexType
=
IndexType
.
createUnique
(
persistent
,
hash
);
}
else
if
(
affinity
)
{
indexType
=
IndexType
.
createAffinity
();
}
else
{
}
else
{
indexType
=
IndexType
.
createNonUnique
(
persistent
,
hash
,
spatial
);
indexType
=
IndexType
.
createNonUnique
(
persistent
,
hash
,
spatial
);
}
}
...
@@ -123,6 +125,10 @@ public class CreateIndex extends SchemaCommand {
...
@@ -123,6 +125,10 @@ public class CreateIndex extends SchemaCommand {
this
.
spatial
=
b
;
this
.
spatial
=
b
;
}
}
public
void
setAffinity
(
boolean
b
)
{
this
.
affinity
=
b
;
}
public
void
setComment
(
String
comment
)
{
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
this
.
comment
=
comment
;
}
}
...
...
h2/src/main/org/h2/command/ddl/CreateTableData.java
浏览文件 @
8fbe0e15
...
@@ -80,5 +80,4 @@ public class CreateTableData {
...
@@ -80,5 +80,4 @@ public class CreateTableData {
* The table is hidden.
* The table is hidden.
*/
*/
public
boolean
isHidden
;
public
boolean
isHidden
;
}
}
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
8fbe0e15
...
@@ -155,6 +155,11 @@ public class Mode {
...
@@ -155,6 +155,11 @@ public class Mode {
*/
*/
public
boolean
prohibitEmptyInPredicate
;
public
boolean
prohibitEmptyInPredicate
;
/**
* Whether AFFINITY KEY keywords are supported.
*/
public
boolean
allowAffinityKey
;
private
final
String
name
;
private
final
String
name
;
static
{
static
{
...
@@ -252,6 +257,12 @@ public class Mode {
...
@@ -252,6 +257,12 @@ public class Mode {
Pattern
.
compile
(
"ApplicationName"
);
Pattern
.
compile
(
"ApplicationName"
);
mode
.
prohibitEmptyInPredicate
=
true
;
mode
.
prohibitEmptyInPredicate
=
true
;
add
(
mode
);
add
(
mode
);
mode
=
new
Mode
(
"Ignite"
);
mode
.
nullConcatIsNull
=
true
;
mode
.
allowAffinityKey
=
true
;
mode
.
indexDefinitionInCreateTable
=
true
;
add
(
mode
);
}
}
private
Mode
(
String
name
)
{
private
Mode
(
String
name
)
{
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
8fbe0e15
...
@@ -13,12 +13,12 @@ import java.util.LinkedList;
...
@@ -13,12 +13,12 @@ import java.util.LinkedList;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Command
;
import
org.h2.command.Command
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.command.ddl.Analyze
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.SetTypes
;
import
org.h2.command.dml.SetTypes
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
...
@@ -126,6 +126,11 @@ public class Session extends SessionWithState {
...
@@ -126,6 +126,11 @@ public class Session extends SessionWithState {
private
boolean
joinBatchEnabled
;
private
boolean
joinBatchEnabled
;
private
boolean
forceJoinOrder
;
private
boolean
forceJoinOrder
;
private
boolean
lazyQueryExecution
;
private
boolean
lazyQueryExecution
;
/**
* Tables marked for ANALYZE after the current transaction is committed.
* Prevents us calling ANALYZE repeatedly in large transactions.
*/
private
HashSet
<
Table
>
tablesToAnalyze
;
/**
/**
* Temporary LOBs from result sets. Those are kept for some time. The
* Temporary LOBs from result sets. Those are kept for some time. The
...
@@ -659,6 +664,14 @@ public class Session extends SessionWithState {
...
@@ -659,6 +664,14 @@ public class Session extends SessionWithState {
}
}
}
}
endTransaction
();
endTransaction
();
int
rows
=
getDatabase
().
getSettings
().
analyzeSample
/
10
;
if
(
tablesToAnalyze
!=
null
)
{
for
(
Table
table
:
tablesToAnalyze
)
{
Analyze
.
analyzeTable
(
this
,
table
,
rows
,
false
);
}
}
tablesToAnalyze
=
null
;
}
}
private
void
removeTemporaryLobs
(
boolean
onTimeout
)
{
private
void
removeTemporaryLobs
(
boolean
onTimeout
)
{
...
@@ -1682,6 +1695,13 @@ public class Session extends SessionWithState {
...
@@ -1682,6 +1695,13 @@ public class Session extends SessionWithState {
return
false
;
return
false
;
}
}
public
void
markTableForAnalyze
(
Table
table
)
{
if
(
tablesToAnalyze
==
null
)
{
tablesToAnalyze
=
New
.
hashSet
();
}
tablesToAnalyze
.
add
(
table
);
}
/**
/**
* Represents a savepoint (a position in a transaction to where one can roll
* Represents a savepoint (a position in a transaction to where one can roll
* back to).
* back to).
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
8fbe0e15
...
@@ -1234,7 +1234,11 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1234,7 +1234,11 @@ public class Function extends Expression implements FunctionCall {
break
;
break
;
case
ROUND:
{
case
ROUND:
{
double
f
=
v1
==
null
?
1
.
:
Math
.
pow
(
10
.,
v1
.
getDouble
());
double
f
=
v1
==
null
?
1
.
:
Math
.
pow
(
10
.,
v1
.
getDouble
());
result
=
ValueDouble
.
get
(
Math
.
round
(
v0
.
getDouble
()
*
f
)
/
f
);
double
middleResult
=
v0
.
getDouble
()
*
f
;
int
oneWithSymbol
=
middleResult
>
0
?
1
:
-
1
;
result
=
ValueDouble
.
get
(
Math
.
round
(
Math
.
abs
(
middleResult
))
/
f
*
oneWithSymbol
);
break
;
break
;
}
}
case
TRUNCATE:
{
case
TRUNCATE:
{
...
...
h2/src/main/org/h2/index/IndexType.java
浏览文件 @
8fbe0e15
...
@@ -10,7 +10,7 @@ package org.h2.index;
...
@@ -10,7 +10,7 @@ package org.h2.index;
*/
*/
public
class
IndexType
{
public
class
IndexType
{
private
boolean
primaryKey
,
persistent
,
unique
,
hash
,
scan
,
spatial
;
private
boolean
primaryKey
,
persistent
,
unique
,
hash
,
scan
,
spatial
,
affinity
;
private
boolean
belongsToConstraint
;
private
boolean
belongsToConstraint
;
/**
/**
...
@@ -71,6 +71,16 @@ public class IndexType {
...
@@ -71,6 +71,16 @@ public class IndexType {
return
type
;
return
type
;
}
}
/**
* Create an affinity index.
*
*/
public
static
IndexType
createAffinity
()
{
IndexType
type
=
new
IndexType
();
type
.
affinity
=
true
;
return
type
;
}
/**
/**
* Create a scan pseudo-index.
* Create a scan pseudo-index.
*
*
...
@@ -148,6 +158,15 @@ public class IndexType {
...
@@ -148,6 +158,15 @@ public class IndexType {
return
unique
;
return
unique
;
}
}
/**
* Does this index represent an affinity key?
*
* @return true if it does
*/
public
boolean
isAffinity
()
{
return
affinity
;
}
/**
/**
* Get the SQL snippet to create such an index.
* Get the SQL snippet to create such an index.
*
*
...
...
h2/src/main/org/h2/message/TraceSystem.java
浏览文件 @
8fbe0e15
...
@@ -146,6 +146,9 @@ public class TraceSystem implements TraceWriter {
...
@@ -146,6 +146,9 @@ public class TraceSystem implements TraceWriter {
@Override
@Override
public
boolean
isEnabled
(
int
level
)
{
public
boolean
isEnabled
(
int
level
)
{
if
(
levelMax
==
ADAPTER
)
{
return
writer
.
isEnabled
(
level
);
}
return
level
<=
this
.
levelMax
;
return
level
<=
this
.
levelMax
;
}
}
...
...
h2/src/main/org/h2/mvstore/WriteBuffer.java
浏览文件 @
8fbe0e15
...
@@ -185,7 +185,7 @@ public class WriteBuffer {
...
@@ -185,7 +185,7 @@ public class WriteBuffer {
* @return this
* @return this
*/
*/
public
WriteBuffer
put
(
ByteBuffer
src
)
{
public
WriteBuffer
put
(
ByteBuffer
src
)
{
ensureCapacity
(
buff
.
remaining
()).
put
(
src
);
ensureCapacity
(
src
.
remaining
()).
put
(
src
);
return
this
;
return
this
;
}
}
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
8fbe0e15
...
@@ -12,10 +12,8 @@ import java.util.Comparator;
...
@@ -12,10 +12,8 @@ import java.util.Comparator;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.ddl.Analyze
;
import
org.h2.command.ddl.CreateTableData
;
import
org.h2.command.ddl.CreateTableData
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintReferential
;
...
@@ -738,7 +736,7 @@ public class MVTable extends TableBase {
...
@@ -738,7 +736,7 @@ public class MVTable extends TableBase {
nextAnalyze
=
n
;
nextAnalyze
=
n
;
}
}
int
rows
=
session
.
getDatabase
().
getSettings
().
analyzeSample
/
10
;
int
rows
=
session
.
getDatabase
().
getSettings
().
analyzeSample
/
10
;
Analyze
.
analyzeTable
(
session
,
this
,
rows
,
false
);
session
.
markTableForAnalyze
(
this
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
8fbe0e15
...
@@ -350,8 +350,12 @@ public class TransactionStore {
...
@@ -350,8 +350,12 @@ public class TransactionStore {
if
(
value
==
null
)
{
if
(
value
==
null
)
{
// nothing to do
// nothing to do
}
else
if
(
value
.
value
==
null
)
{
}
else
if
(
value
.
value
==
null
)
{
int
tx
=
getTransactionId
(
value
.
operationId
);
if
(
tx
==
t
.
transactionId
)
{
// remove the value
// remove the value
// only if it's transaction id is same as current transaction id
map
.
remove
(
key
);
map
.
remove
(
key
);
}
}
else
{
}
else
{
VersionedValue
v2
=
new
VersionedValue
();
VersionedValue
v2
=
new
VersionedValue
();
v2
.
value
=
value
.
value
;
v2
.
value
=
value
.
value
;
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
8fbe0e15
...
@@ -149,9 +149,9 @@ ALTER VIEW [ IF EXISTS ] viewName RECOMPILE
...
@@ -149,9 +149,9 @@ ALTER VIEW [ IF EXISTS ] viewName RECOMPILE
","
","
Recompiles a view after the underlying tables have been changed or created."
Recompiles a view after the underlying tables have been changed or created."
"Commands (DDL)","ANALYZE","
"Commands (DDL)","ANALYZE","
ANALYZE [ SAMPLE_SIZE rowCountInt ]
ANALYZE [
TABLE tableName ] [
SAMPLE_SIZE rowCountInt ]
","
","
Updates the selectivity statistics of
all
tables."
Updates the selectivity statistics of tables."
"Commands (DDL)","COMMENT","
"Commands (DDL)","COMMENT","
COMMENT ON
COMMENT ON
{ { COLUMN [ schemaName. ] tableName.columnName }
{ { COLUMN [ schemaName. ] tableName.columnName }
...
...
h2/src/main/org/h2/table/JoinBatch.java
浏览文件 @
8fbe0e15
...
@@ -167,6 +167,9 @@ public final class JoinBatch {
...
@@ -167,6 +167,9 @@ public final class JoinBatch {
* @return column value for current row
* @return column value for current row
*/
*/
public
Value
getValue
(
int
filterId
,
Column
column
)
{
public
Value
getValue
(
int
filterId
,
Column
column
)
{
if
(
current
==
null
)
{
return
null
;
}
Object
x
=
current
.
row
(
filterId
);
Object
x
=
current
.
row
(
filterId
);
assert
x
!=
null
;
assert
x
!=
null
;
Row
row
=
current
.
isRow
(
filterId
)
?
(
Row
)
x
:
((
Cursor
)
x
).
get
();
Row
row
=
current
.
isRow
(
filterId
)
?
(
Row
)
x
:
((
Cursor
)
x
).
get
();
...
...
h2/src/main/org/h2/table/LinkSchema.java
浏览文件 @
8fbe0e15
...
@@ -52,7 +52,12 @@ public class LinkSchema {
...
@@ -52,7 +52,12 @@ public class LinkSchema {
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE SCHEMA IF NOT EXISTS "
+
stat
.
execute
(
"CREATE SCHEMA IF NOT EXISTS "
+
StringUtils
.
quoteIdentifier
(
targetSchema
));
StringUtils
.
quoteIdentifier
(
targetSchema
));
//Workaround for PostgreSQL to avoid index names
if
(
url
.
startsWith
(
"jdbc:postgresql:"
))
{
rs
=
c2
.
getMetaData
().
getTables
(
null
,
sourceSchema
,
null
,
new
String
[]{
"TABLE"
,
"LINKED TABLE"
,
"VIEW"
,
"EXTERNAL"
});
}
else
{
rs
=
c2
.
getMetaData
().
getTables
(
null
,
sourceSchema
,
null
,
null
);
rs
=
c2
.
getMetaData
().
getTables
(
null
,
sourceSchema
,
null
,
null
);
}
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
String
table
=
rs
.
getString
(
"TABLE_NAME"
);
String
table
=
rs
.
getString
(
"TABLE_NAME"
);
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
8fbe0e15
...
@@ -200,7 +200,8 @@ public class MetaTable extends Table {
...
@@ -200,7 +200,8 @@ public class MetaTable extends Table {
"ID INT"
,
"ID INT"
,
"SORT_TYPE INT"
,
"SORT_TYPE INT"
,
"CONSTRAINT_NAME"
,
"CONSTRAINT_NAME"
,
"INDEX_CLASS"
"INDEX_CLASS"
,
"AFFINITY BIT"
);
);
indexColumnName
=
"TABLE_NAME"
;
indexColumnName
=
"TABLE_NAME"
;
break
;
break
;
...
@@ -912,7 +913,10 @@ public class MetaTable extends Table {
...
@@ -912,7 +913,10 @@ public class MetaTable extends Table {
// CONSTRAINT_NAME
// CONSTRAINT_NAME
constraintName
,
constraintName
,
// INDEX_CLASS
// INDEX_CLASS
indexClass
indexClass
,
// AFFINITY
index
.
getIndexType
().
isAffinity
()
?
"TRUE"
:
"FALSE"
);
);
}
}
}
}
...
...
h2/src/main/org/h2/table/RegularTable.java
浏览文件 @
8fbe0e15
...
@@ -12,10 +12,8 @@ import java.util.Comparator;
...
@@ -12,10 +12,8 @@ import java.util.Comparator;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.ddl.Analyze
;
import
org.h2.command.ddl.CreateTableData
;
import
org.h2.command.ddl.CreateTableData
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.constraint.ConstraintReferential
;
...
@@ -431,8 +429,7 @@ public class RegularTable extends TableBase {
...
@@ -431,8 +429,7 @@ public class RegularTable extends TableBase {
if
(
n
>
0
)
{
if
(
n
>
0
)
{
nextAnalyze
=
n
;
nextAnalyze
=
n
;
}
}
int
rows
=
session
.
getDatabase
().
getSettings
().
analyzeSample
/
10
;
session
.
markTableForAnalyze
(
this
);
Analyze
.
analyzeTable
(
session
,
this
,
rows
,
false
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
8fbe0e15
...
@@ -445,7 +445,8 @@ public class TableLink extends Table {
...
@@ -445,7 +445,8 @@ public class TableLink extends Table {
@Override
@Override
public
synchronized
long
getRowCount
(
Session
session
)
{
public
synchronized
long
getRowCount
(
Session
session
)
{
String
sql
=
"SELECT COUNT(*) FROM "
+
qualifiedTableName
;
//The foo alias is used to support the PostgreSQL syntax
String
sql
=
"SELECT COUNT(*) FROM "
+
qualifiedTableName
+
" as foo"
;
try
{
try
{
PreparedStatement
prep
=
execute
(
sql
,
null
,
false
);
PreparedStatement
prep
=
execute
(
sql
,
null
,
false
);
ResultSet
rs
=
prep
.
getResultSet
();
ResultSet
rs
=
prep
.
getResultSet
();
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
8fbe0e15
...
@@ -117,6 +117,7 @@ import org.h2.test.mvcc.TestMvcc2;
...
@@ -117,6 +117,7 @@ import org.h2.test.mvcc.TestMvcc2;
import
org.h2.test.mvcc.TestMvcc3
;
import
org.h2.test.mvcc.TestMvcc3
;
import
org.h2.test.mvcc.TestMvcc4
;
import
org.h2.test.mvcc.TestMvcc4
;
import
org.h2.test.mvcc.TestMvccMultiThreaded
;
import
org.h2.test.mvcc.TestMvccMultiThreaded
;
import
org.h2.test.mvcc.TestMvccMultiThreaded2
;
import
org.h2.test.poweroff.TestReorderWrites
;
import
org.h2.test.poweroff.TestReorderWrites
;
import
org.h2.test.recover.RecoverLobTest
;
import
org.h2.test.recover.RecoverLobTest
;
import
org.h2.test.rowlock.TestRowLocks
;
import
org.h2.test.rowlock.TestRowLocks
;
...
@@ -803,6 +804,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
...
@@ -803,6 +804,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest
(
new
TestMvcc3
());
addTest
(
new
TestMvcc3
());
addTest
(
new
TestMvcc4
());
addTest
(
new
TestMvcc4
());
addTest
(
new
TestMvccMultiThreaded
());
addTest
(
new
TestMvccMultiThreaded
());
addTest
(
new
TestMvccMultiThreaded2
());
addTest
(
new
TestRowLocks
());
addTest
(
new
TestRowLocks
());
// synth
// synth
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
8fbe0e15
...
@@ -50,6 +50,7 @@ public class TestCompatibility extends TestBase {
...
@@ -50,6 +50,7 @@ public class TestCompatibility extends TestBase {
testDB2
();
testDB2
();
testDerby
();
testDerby
();
testSybaseAndMSSQLServer
();
testSybaseAndMSSQLServer
();
testIgnite
();
conn
.
close
();
conn
.
close
();
deleteDb
(
"compatibility"
);
deleteDb
(
"compatibility"
);
...
@@ -487,4 +488,26 @@ public class TestCompatibility extends TestBase {
...
@@ -487,4 +488,26 @@ public class TestCompatibility extends TestBase {
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"compatibility"
);
conn
=
getConnection
(
"compatibility"
);
}
}
private
void
testIgnite
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET MODE Ignite"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int affinity key)"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int affinity primary key)"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int, v1 varchar, v2 long affinity key, primary key(v1, id))"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int, v1 varchar, v2 long, primary key(v1, id), affinity key (id))"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int shard key)"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int shard primary key)"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int, v1 varchar, v2 long shard key, primary key(v1, id))"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"create table test(id int, v1 varchar, v2 long, primary key(v1, id), shard key (id))"
);
}
}
}
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
8fbe0e15
...
@@ -117,6 +117,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -117,6 +117,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testThatCurrentTimestampStaysTheSameWithinATransaction
();
testThatCurrentTimestampStaysTheSameWithinATransaction
();
testThatCurrentTimestampUpdatesOutsideATransaction
();
testThatCurrentTimestampUpdatesOutsideATransaction
();
testAnnotationProcessorsOutput
();
testAnnotationProcessorsOutput
();
testRound
();
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
}
}
...
@@ -2010,6 +2011,28 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -2010,6 +2011,28 @@ public class TestFunctions extends TestBase implements AggregateFunction {
}
}
}
}
private
void
testRound
()
throws
SQLException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
final
ResultSet
rs
=
stat
.
executeQuery
(
"select ROUND(-1.2), ROUND(-1.5), ROUND(-1.6), ROUND(2), ROUND(1.5), ROUND(1.8), ROUND(1.1) from dual"
);
rs
.
next
();
assertEquals
(-
1
,
rs
.
getInt
(
1
));
assertEquals
(-
2
,
rs
.
getInt
(
2
));
assertEquals
(-
2
,
rs
.
getInt
(
3
));
assertEquals
(
2
,
rs
.
getInt
(
4
));
assertEquals
(
2
,
rs
.
getInt
(
5
));
assertEquals
(
2
,
rs
.
getInt
(
6
));
assertEquals
(
1
,
rs
.
getInt
(
7
));
rs
.
close
();
conn
.
close
();
}
private
void
testThatCurrentTimestampIsSane
()
throws
SQLException
,
private
void
testThatCurrentTimestampIsSane
()
throws
SQLException
,
ParseException
{
ParseException
{
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
...
...
h2/src/test/org/h2/test/db/TestQueryCache.java
浏览文件 @
8fbe0e15
...
@@ -38,30 +38,45 @@ public class TestQueryCache extends TestBase {
...
@@ -38,30 +38,45 @@ public class TestQueryCache extends TestBase {
private
void
test1
()
throws
Exception
{
private
void
test1
()
throws
Exception
{
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
);
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar) "
+
stat
.
execute
(
"create table test(id int, name varchar)"
);
"as select x, space(100) from system_range(1, 1000)"
);
PreparedStatement
prep
;
PreparedStatement
prep
;
conn
.
prepareStatement
(
"select count(*) from test t1, test t2"
);
// query execution may be fast here but the parsing must be slow
StringBuilder
queryBuilder
=
new
StringBuilder
(
"select count(*) from test t1 where \n"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
if
(
i
!=
0
)
{
queryBuilder
.
append
(
" and "
);
}
queryBuilder
.
append
(
" TIMESTAMP '2005-12-31 23:59:59' = TIMESTAMP '2005-12-31 23:59:59' "
);
}
String
query
=
queryBuilder
.
toString
();
conn
.
prepareStatement
(
query
);
long
time
;
long
time
;
ResultSet
rs
;
ResultSet
rs
;
long
first
=
0
;
long
first
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
// 1000 iterations to warm up and avoid JIT effects
for
(
int
i
=
0
;
i
<
1005
;
i
++)
{
// this should both ensure results are not re-used
// this should both ensure results are not re-used
// stat.execute("set mode regular");
// stat.execute("set mode regular");
// stat.execute("create table x()");
// stat.execute("create table x()");
// stat.execute("drop table x");
// stat.execute("drop table x");
time
=
System
.
nanoTime
();
time
=
System
.
nanoTime
();
prep
=
conn
.
prepareStatement
(
"select count(*) from test t1, test t2"
);
prep
=
conn
.
prepareStatement
(
query
);
execute
(
prep
);
execute
(
prep
);
rs
=
stat
.
executeQuery
(
"select count(*) from test t1, test t2"
);
prep
.
close
();
rs
=
stat
.
executeQuery
(
query
);
rs
.
next
();
rs
.
next
();
int
c
=
rs
.
getInt
(
1
);
int
c
=
rs
.
getInt
(
1
);
rs
.
close
();
rs
.
close
();
assertEquals
(
100000
0
,
c
);
assertEquals
(
0
,
c
);
time
=
System
.
nanoTime
()
-
time
;
time
=
System
.
nanoTime
()
-
time
;
if
(
first
==
0
)
{
if
(
i
==
1000
)
{
// take from cache and do not close, so that next iteration will have a cache miss
prep
=
conn
.
prepareStatement
(
query
);
}
else
if
(
i
==
1001
)
{
first
=
time
;
first
=
time
;
}
else
{
// try to avoid pauses in subsequent iterations
System
.
gc
();
}
else
if
(
i
>
1001
)
{
assertSmaller
(
time
,
first
);
assertSmaller
(
time
,
first
);
}
}
}
}
...
...
h2/src/test/org/h2/test/db/TestTableEngines.java
浏览文件 @
8fbe0e15
...
@@ -41,13 +41,7 @@ import org.h2.message.DbException;
...
@@ -41,13 +41,7 @@ import org.h2.message.DbException;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.result.SortOrder
;
import
org.h2.table.Column
;
import
org.h2.table.*
;
import
org.h2.table.IndexColumn
;
import
org.h2.table.SubQueryInfo
;
import
org.h2.table.Table
;
import
org.h2.table.TableBase
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableType
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.util.DoneFuture
;
import
org.h2.util.DoneFuture
;
import
org.h2.util.New
;
import
org.h2.util.New
;
...
@@ -82,6 +76,7 @@ public class TestTableEngines extends TestBase {
...
@@ -82,6 +76,7 @@ public class TestTableEngines extends TestBase {
testSimpleQuery
();
testSimpleQuery
();
testMultiColumnTreeSetIndex
();
testMultiColumnTreeSetIndex
();
testBatchedJoin
();
testBatchedJoin
();
testAffinityKey
();
}
}
private
void
testEarlyFilter
()
throws
SQLException
{
private
void
testEarlyFilter
()
throws
SQLException
{
...
@@ -504,6 +499,25 @@ public class TestTableEngines extends TestBase {
...
@@ -504,6 +499,25 @@ public class TestTableEngines extends TestBase {
deleteDb
(
"testBatchedJoin"
);
deleteDb
(
"testBatchedJoin"
);
}
}
private
void
testAffinityKey
()
throws
SQLException
{
deleteDb
(
"tableEngine"
);
Connection
conn
=
getConnection
(
"tableEngine;mode=Ignite;MV_STORE=FALSE"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
executeUpdate
(
"CREATE TABLE T(ID INT AFFINITY PRIMARY KEY, NAME VARCHAR, AGE INT)"
+
" ENGINE \""
+
AffinityTableEngine
.
class
.
getName
()
+
"\""
);
Table
tbl
=
AffinityTableEngine
.
createdTbl
;
assertTrue
(
tbl
!=
null
);
assertEquals
(
3
,
tbl
.
getIndexes
().
size
());
Index
aff
=
tbl
.
getIndexes
().
get
(
2
);
assertTrue
(
aff
.
getIndexType
().
isAffinity
());
assertEquals
(
"T_AFF"
,
aff
.
getName
());
assertEquals
(
1
,
aff
.
getIndexColumns
().
length
);
assertEquals
(
"ID"
,
aff
.
getIndexColumns
()[
0
].
columnName
);
conn
.
close
();
deleteDb
(
"tableEngine"
);
}
private
static
void
forceJoinOrder
(
Statement
s
,
boolean
force
)
throws
SQLException
{
private
static
void
forceJoinOrder
(
Statement
s
,
boolean
force
)
throws
SQLException
{
s
.
executeUpdate
(
"SET FORCE_JOIN_ORDER "
+
force
);
s
.
executeUpdate
(
"SET FORCE_JOIN_ORDER "
+
force
);
}
}
...
@@ -1098,6 +1112,144 @@ public class TestTableEngines extends TestBase {
...
@@ -1098,6 +1112,144 @@ public class TestTableEngines extends TestBase {
}
}
/**
* A test table factory producing affinity aware tables.
*/
public
static
class
AffinityTableEngine
implements
TableEngine
{
public
static
Table
createdTbl
;
/**
* A table able to handle affinity indexes.
*/
private
static
class
AffinityTable
extends
RegularTable
{
/**
* A (no-op) affinity index.
*/
public
class
AffinityIndex
extends
BaseIndex
{
AffinityIndex
(
Table
table
,
int
id
,
String
name
,
IndexColumn
[]
newIndexColumns
)
{
initBaseIndex
(
table
,
id
,
name
,
newIndexColumns
,
IndexType
.
createAffinity
());
}
@Override
public
long
getRowCountApproximation
()
{
return
table
.
getRowCountApproximation
();
}
@Override
public
long
getDiskSpaceUsed
()
{
return
table
.
getDiskSpaceUsed
();
}
@Override
public
long
getRowCount
(
Session
session
)
{
return
table
.
getRowCount
(
session
);
}
@Override
public
void
checkRename
()
{
// do nothing
}
@Override
public
void
truncate
(
Session
session
)
{
// do nothing
}
@Override
public
void
remove
(
Session
session
)
{
// do nothing
}
@Override
public
void
remove
(
Session
session
,
Row
r
)
{
// do nothing
}
@Override
public
boolean
needRebuild
()
{
return
false
;
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
,
HashSet
<
Column
>
allColumnsSet
)
{
return
0
;
}
@Override
public
Cursor
findFirstOrLast
(
Session
session
,
boolean
first
)
{
throw
DbException
.
getUnsupportedException
(
"TEST"
);
}
@Override
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
{
throw
DbException
.
getUnsupportedException
(
"TEST"
);
}
@Override
public
void
close
(
Session
session
)
{
// do nothing
}
@Override
public
boolean
canGetFirstOrLast
()
{
return
false
;
}
@Override
public
void
add
(
Session
session
,
Row
r
)
{
// do nothing
}
}
AffinityTable
(
CreateTableData
data
)
{
super
(
data
);
}
@Override
public
Index
addIndex
(
Session
session
,
String
indexName
,
int
indexId
,
IndexColumn
[]
cols
,
IndexType
indexType
,
boolean
create
,
String
indexComment
)
{
if
(!
indexType
.
isAffinity
())
{
return
super
.
addIndex
(
session
,
indexName
,
indexId
,
cols
,
indexType
,
create
,
indexComment
);
}
boolean
isSessionTemporary
=
isTemporary
()
&&
!
isGlobalTemporary
();
if
(!
isSessionTemporary
)
{
database
.
lockMeta
(
session
);
}
AffinityIndex
index
=
new
AffinityIndex
(
this
,
indexId
,
getName
()
+
"_AFF"
,
cols
);
index
.
setTemporary
(
isTemporary
());
if
(
index
.
getCreateSQL
()
!=
null
)
{
index
.
setComment
(
indexComment
);
if
(
isSessionTemporary
)
{
session
.
addLocalTempTableIndex
(
index
);
}
else
{
database
.
addSchemaObject
(
session
,
index
);
}
}
getIndexes
().
add
(
index
);
setModified
();
return
index
;
}
}
/**
* Create a new OneRowTable.
*
* @param data the meta data of the table to create
* @return the new table
*/
@Override
public
Table
createTable
(
CreateTableData
data
)
{
return
(
createdTbl
=
new
AffinityTable
(
data
));
}
}
/**
/**
* A test table factory.
* A test table factory.
*/
*/
...
...
h2/src/test/org/h2/test/mvcc/TestMvccMultiThreaded2.java
0 → 100644
浏览文件 @
8fbe0e15
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
mvcc
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
org.h2.api.ErrorCode
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
* Additional MVCC (multi version concurrency) test cases.
*/
public
class
TestMvccMultiThreaded2
extends
TestBase
{
private
static
final
String
URL
=
";MVCC=TRUE;LOCK_TIMEOUT=120000;MULTI_THREADED=TRUE"
;
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
test
=
TestBase
.
createCaller
().
init
();
test
.
config
.
mvcc
=
true
;
test
.
config
.
lockTimeout
=
120000
;
test
.
config
.
memory
=
true
;
test
.
config
.
multiThreaded
=
true
;
test
.
test
();
}
@Override
public
void
test
()
throws
SQLException
,
InterruptedException
{
testSelectForUpdateConcurrency
();
}
private
void
testSelectForUpdateConcurrency
()
throws
SQLException
,
InterruptedException
{
deleteDb
(
getTestName
());
Connection
conn
=
getConnection
(
getTestName
()
+
URL
);
conn
.
setAutoCommit
(
false
);
String
sql
=
"CREATE TABLE test ("
+
"entity_id INTEGER NOT NULL PRIMARY KEY, "
+
"lastUpdated INTEGER NOT NULL)"
;
Statement
smtm
=
conn
.
createStatement
();
smtm
.
executeUpdate
(
sql
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
"INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)"
);
ps
.
setInt
(
1
,
1
);
ps
.
setInt
(
2
,
100
);
ps
.
executeUpdate
();
conn
.
commit
();
ArrayList
<
SelectForUpdate
>
threads
=
new
ArrayList
<
SelectForUpdate
>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
SelectForUpdate
sfu
=
new
SelectForUpdate
();
threads
.
add
(
sfu
);
sfu
.
start
();
}
for
(
SelectForUpdate
sfu
:
threads
)
{
sfu
.
join
();
}
IOUtils
.
closeSilently
(
conn
);
deleteDb
(
getTestName
());
}
private
class
SelectForUpdate
extends
Thread
{
@Override
public
void
run
()
{
final
long
start
=
System
.
currentTimeMillis
();
boolean
done
=
false
;
Connection
conn
=
null
;
try
{
conn
=
getConnection
(
getTestName
()
+
URL
);
conn
.
setAutoCommit
(
false
);
while
(!
done
)
{
try
{
PreparedStatement
ps
=
conn
.
prepareStatement
(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE"
);
ps
.
setString
(
1
,
"1"
);
ResultSet
rs
=
ps
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
getInt
(
2
)
==
100
);
conn
.
commit
();
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
start
>
1000
*
60
)
done
=
true
;
}
catch
(
JdbcSQLException
e1
)
{
// skip DUPLICATE_KEY_1 to just focus on this bug.
if
(
e1
.
getErrorCode
()
!=
ErrorCode
.
DUPLICATE_KEY_1
)
{
throw
e1
;
}
}
}
}
catch
(
SQLException
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
IOUtils
.
closeSilently
(
conn
);
}
}
}
h2/src/test/org/h2/test/unit/TestTraceSystem.java
浏览文件 @
8fbe0e15
...
@@ -32,13 +32,19 @@ public class TestTraceSystem extends TestBase {
...
@@ -32,13 +32,19 @@ public class TestTraceSystem extends TestBase {
testAdapter
();
testAdapter
();
}
}
private
static
void
testAdapter
()
{
private
void
testAdapter
()
{
TraceSystem
ts
=
new
TraceSystem
(
null
);
TraceSystem
ts
=
new
TraceSystem
(
null
);
ts
.
setName
(
"test"
);
ts
.
setName
(
"test"
);
ts
.
setLevelFile
(
TraceSystem
.
ADAPTER
);
ts
.
setLevelFile
(
TraceSystem
.
ADAPTER
);
ts
.
getTrace
(
"test"
).
debug
(
"test"
);
ts
.
getTrace
(
"test"
).
debug
(
"test"
);
ts
.
getTrace
(
"test"
).
info
(
"test"
);
ts
.
getTrace
(
"test"
).
info
(
"test"
);
ts
.
getTrace
(
"test"
).
error
(
new
Exception
(),
"test"
);
ts
.
getTrace
(
"test"
).
error
(
new
Exception
(),
"test"
);
// The used SLF4J-nop logger has all log levels disabled,
// so this should be reflected in the trace system.
assertFalse
(
ts
.
isEnabled
(
TraceSystem
.
INFO
));
assertFalse
(
ts
.
getTrace
(
"test"
).
isInfoEnabled
());
ts
.
close
();
ts
.
close
();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论