Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
79ba7f42
提交
79ba7f42
authored
8月 16, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
774b1795
隐藏空白字符变更
内嵌
并排
正在显示
53 个修改的文件
包含
759 行增加
和
162 行删除
+759
-162
Parser.java
h2/src/main/org/h2/command/Parser.java
+0
-1
AlterIndexRename.java
h2/src/main/org/h2/command/ddl/AlterIndexRename.java
+0
-1
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+0
-1
AlterTableRenameColumn.java
h2/src/main/org/h2/command/ddl/AlterTableRenameColumn.java
+0
-1
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+0
-1
DropDatabase.java
h2/src/main/org/h2/command/ddl/DropDatabase.java
+0
-1
DropIndex.java
h2/src/main/org/h2/command/ddl/DropIndex.java
+0
-1
SetComment.java
h2/src/main/org/h2/command/ddl/SetComment.java
+0
-1
Select.java
h2/src/main/org/h2/command/dml/Select.java
+2
-3
Constraint.java
h2/src/main/org/h2/constraint/Constraint.java
+2
-2
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+0
-1
ConstraintUnique.java
h2/src/main/org/h2/constraint/ConstraintUnique.java
+0
-1
Comment.java
h2/src/main/org/h2/engine/Comment.java
+1
-1
Database.java
h2/src/main/org/h2/engine/Database.java
+0
-1
DbObjectBase.java
h2/src/main/org/h2/engine/DbObjectBase.java
+150
-0
FunctionAlias.java
h2/src/main/org/h2/engine/FunctionAlias.java
+1
-1
MetaRecord.java
h2/src/main/org/h2/engine/MetaRecord.java
+2
-2
Right.java
h2/src/main/org/h2/engine/Right.java
+1
-1
RightOwner.java
h2/src/main/org/h2/engine/RightOwner.java
+1
-1
Setting.java
h2/src/main/org/h2/engine/Setting.java
+1
-1
UserDataType.java
h2/src/main/org/h2/engine/UserDataType.java
+1
-1
Aggregate.java
h2/src/main/org/h2/expression/Aggregate.java
+3
-1
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+252
-0
BtreeCursor.java
h2/src/main/org/h2/index/BtreeCursor.java
+0
-11
BtreeIndex.java
h2/src/main/org/h2/index/BtreeIndex.java
+13
-22
BtreeLeaf.java
h2/src/main/org/h2/index/BtreeLeaf.java
+2
-15
BtreeNode.java
h2/src/main/org/h2/index/BtreeNode.java
+0
-1
FunctionIndex.java
h2/src/main/org/h2/index/FunctionIndex.java
+2
-4
HashIndex.java
h2/src/main/org/h2/index/HashIndex.java
+2
-2
LinearHashIndex.java
h2/src/main/org/h2/index/LinearHashIndex.java
+2
-2
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+2
-2
MetaIndex.java
h2/src/main/org/h2/index/MetaIndex.java
+2
-4
MultiVersionCursor.java
h2/src/main/org/h2/index/MultiVersionCursor.java
+40
-0
MultiVersionIndex.java
h2/src/main/org/h2/index/MultiVersionIndex.java
+209
-0
RangeIndex.java
h2/src/main/org/h2/index/RangeIndex.java
+3
-3
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+2
-2
TreeIndex.java
h2/src/main/org/h2/index/TreeIndex.java
+8
-8
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+3
-4
help.csv
h2/src/main/org/h2/res/help.csv
+1
-1
SearchRow.java
h2/src/main/org/h2/result/SearchRow.java
+0
-4
SimpleRow.java
h2/src/main/org/h2/result/SimpleRow.java
+0
-17
SimpleRowValue.java
h2/src/main/org/h2/result/SimpleRowValue.java
+0
-17
Constant.java
h2/src/main/org/h2/schema/Constant.java
+1
-1
Schema.java
h2/src/main/org/h2/schema/Schema.java
+3
-1
SchemaObjectBase.java
h2/src/main/org/h2/schema/SchemaObjectBase.java
+26
-0
Sequence.java
h2/src/main/org/h2/schema/Sequence.java
+1
-1
TriggerObject.java
h2/src/main/org/h2/schema/TriggerObject.java
+1
-1
UndoLogRecord.java
h2/src/main/org/h2/store/UndoLogRecord.java
+7
-1
FunctionTable.java
h2/src/main/org/h2/table/FunctionTable.java
+0
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+0
-1
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+0
-1
Table.java
h2/src/main/org/h2/table/Table.java
+3
-4
TableData.java
h2/src/main/org/h2/table/TableData.java
+9
-6
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
79ba7f42
...
...
@@ -9,7 +9,6 @@ import java.math.BigInteger;
import
java.sql.SQLException
;
import
java.text.Collator
;
import
java.util.HashSet
;
import
org.h2.command.ddl.AlterIndexRename
;
import
org.h2.command.ddl.AlterSequence
;
import
org.h2.command.ddl.AlterTableAddConstraint
;
...
...
h2/src/main/org/h2/command/ddl/AlterIndexRename.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Right
;
...
...
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
org.h2.command.Parser
;
import
org.h2.command.Prepared
;
import
org.h2.constant.ErrorCode
;
...
...
h2/src/main/org/h2/command/ddl/AlterTableRenameColumn.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
org.h2.engine.Database
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Right
;
...
...
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
org.h2.command.Prepared
;
import
org.h2.command.dml.Insert
;
import
org.h2.command.dml.Query
;
...
...
h2/src/main/org/h2/command/ddl/DropDatabase.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
org.h2.engine.Database
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Role
;
...
...
h2/src/main/org/h2/command/ddl/DropIndex.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constraint.Constraint
;
import
org.h2.engine.Database
;
...
...
h2/src/main/org/h2/command/ddl/SetComment.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
command
.
ddl
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Comment
;
import
org.h2.engine.Database
;
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
79ba7f42
...
...
@@ -7,7 +7,6 @@ package org.h2.command.dml;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
...
...
@@ -238,7 +237,7 @@ public class Select extends Query {
// can't use the scan index
continue
;
}
if
(
index
.
indexType
.
isHash
())
{
if
(
index
.
getIndexType
()
.
isHash
())
{
continue
;
}
Column
[]
indexCols
=
index
.
getColumns
();
...
...
@@ -490,7 +489,7 @@ public class Select extends Query {
if
(
sort
!=
null
&&
!
isQuickQuery
&&
!
isGroupQuery
&&
!
distinct
)
{
Index
index
=
getSortIndex
();
Index
current
=
topTableFilter
.
getIndex
();
if
(
index
!=
null
&&
(
current
.
indexType
.
isScan
()
||
current
==
index
))
{
if
(
index
!=
null
&&
(
current
.
getIndexType
()
.
isScan
()
||
current
==
index
))
{
topTableFilter
.
setIndex
(
index
);
sort
=
null
;
}
...
...
h2/src/main/org/h2/constraint/Constraint.java
浏览文件 @
79ba7f42
...
...
@@ -12,14 +12,14 @@ import org.h2.index.Index;
import
org.h2.message.Trace
;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.SchemaObject
Base
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
/**
* @author Thomas
*/
public
abstract
class
Constraint
extends
SchemaObject
{
public
abstract
class
Constraint
extends
SchemaObject
Base
{
public
static
final
String
CHECK
=
"CHECK"
,
REFERENTIAL
=
"REFERENTIAL"
,
UNIQUE
=
"UNIQUE"
;
protected
Table
table
;
...
...
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
constraint
;
import
java.sql.SQLException
;
import
org.h2.command.Parser
;
import
org.h2.command.Prepared
;
import
org.h2.constant.ErrorCode
;
...
...
h2/src/main/org/h2/constraint/ConstraintUnique.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
constraint
;
import
java.sql.SQLException
;
import
org.h2.command.Parser
;
import
org.h2.engine.Session
;
import
org.h2.index.Index
;
...
...
h2/src/main/org/h2/engine/Comment.java
浏览文件 @
79ba7f42
...
...
@@ -11,7 +11,7 @@ import org.h2.message.Trace;
import
org.h2.table.Table
;
import
org.h2.util.StringUtils
;
public
class
Comment
extends
DbObject
{
public
class
Comment
extends
DbObject
Base
{
private
final
int
objectType
;
private
final
String
objectName
;
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
79ba7f42
...
...
@@ -11,7 +11,6 @@ import java.util.HashMap;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.StringTokenizer
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.command.dml.SetTypes
;
import
org.h2.constant.ErrorCode
;
...
...
h2/src/main/org/h2/engine/DbObjectBase.java
0 → 100644
浏览文件 @
79ba7f42
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
engine
;
import
java.sql.SQLException
;
import
org.h2.command.Parser
;
import
org.h2.message.Message
;
import
org.h2.message.Trace
;
import
org.h2.table.Table
;
import
org.h2.util.ObjectArray
;
/**
* @author Thomas
*/
public
abstract
class
DbObjectBase
implements
DbObject
{
private
int
id
;
protected
Database
database
;
protected
Trace
trace
;
private
String
objectName
;
private
long
modificationId
;
private
boolean
temporary
;
protected
String
comment
;
protected
DbObjectBase
(
Database
database
,
int
id
,
String
name
,
String
traceModule
)
{
this
.
database
=
database
;
this
.
trace
=
database
.
getTrace
(
traceModule
);
this
.
id
=
id
;
this
.
objectName
=
name
;
this
.
modificationId
=
database
.
getModificationMetaId
();
}
public
void
setModified
()
{
this
.
modificationId
=
database
==
null
?
-
1
:
database
.
getNextModificationMetaId
();
}
public
long
getModificationId
()
{
return
modificationId
;
}
protected
void
setObjectName
(
String
name
)
{
objectName
=
name
;
}
public
String
getSQL
()
{
return
Parser
.
quoteIdentifier
(
objectName
);
}
public
ObjectArray
getChildren
()
{
return
null
;
}
public
Database
getDatabase
()
{
return
database
;
}
public
int
getId
()
{
return
id
;
}
public
String
getName
()
{
return
objectName
;
}
public
abstract
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
);
public
abstract
String
getCreateSQL
();
public
abstract
String
getDropSQL
();
public
abstract
int
getType
();
public
abstract
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
;
public
abstract
void
checkRename
()
throws
SQLException
;
protected
void
invalidate
()
{
setModified
();
id
=
-
1
;
database
=
null
;
trace
=
null
;
objectName
=
null
;
}
public
int
getHeadPos
()
{
return
0
;
}
public
void
rename
(
String
newName
)
throws
SQLException
{
checkRename
();
objectName
=
newName
;
setModified
();
}
public
boolean
getTemporary
()
{
return
temporary
;
}
public
void
setTemporary
(
boolean
temporary
)
{
this
.
temporary
=
temporary
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
}
public
String
getComment
()
{
return
comment
;
}
static
int
getCreateOrder
(
int
type
)
{
switch
(
type
)
{
case
SETTING:
return
0
;
case
USER:
return
1
;
case
SCHEMA:
return
2
;
case
USER_DATATYPE:
return
3
;
case
SEQUENCE:
return
4
;
case
CONSTANT:
return
5
;
case
FUNCTION_ALIAS:
return
6
;
case
TABLE_OR_VIEW:
return
7
;
case
INDEX:
return
8
;
case
CONSTRAINT:
return
9
;
case
TRIGGER:
return
10
;
case
ROLE:
return
11
;
case
RIGHT:
return
12
;
case
COMMENT:
return
13
;
default
:
throw
Message
.
getInternalError
(
"type="
+
type
);
}
}
}
h2/src/main/org/h2/engine/FunctionAlias.java
浏览文件 @
79ba7f42
...
...
@@ -19,7 +19,7 @@ import org.h2.value.DataType;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
public
class
FunctionAlias
extends
DbObject
{
public
class
FunctionAlias
extends
DbObject
Base
{
private
boolean
hasConnectionParam
;
private
String
className
;
...
...
h2/src/main/org/h2/engine/MetaRecord.java
浏览文件 @
79ba7f42
...
...
@@ -35,8 +35,8 @@ public class MetaRecord {
public
int
compare
(
Object
o1
,
Object
o2
)
{
MetaRecord
m1
=
(
MetaRecord
)
o1
;
MetaRecord
m2
=
(
MetaRecord
)
o2
;
int
c1
=
DbObject
.
getCreateOrder
(
m1
.
getObjectType
());
int
c2
=
DbObject
.
getCreateOrder
(
m2
.
getObjectType
());
int
c1
=
DbObject
Base
.
getCreateOrder
(
m1
.
getObjectType
());
int
c2
=
DbObject
Base
.
getCreateOrder
(
m2
.
getObjectType
());
if
(
c1
!=
c2
)
{
return
c1
-
c2
;
}
...
...
h2/src/main/org/h2/engine/Right.java
浏览文件 @
79ba7f42
...
...
@@ -10,7 +10,7 @@ import org.h2.message.Message;
import
org.h2.message.Trace
;
import
org.h2.table.Table
;
public
class
Right
extends
DbObject
{
public
class
Right
extends
DbObject
Base
{
public
static
final
int
SELECT
=
1
,
DELETE
=
2
,
INSERT
=
4
,
UPDATE
=
8
,
ALL
=
15
;
...
...
h2/src/main/org/h2/engine/RightOwner.java
浏览文件 @
79ba7f42
...
...
@@ -12,7 +12,7 @@ import org.h2.constant.ErrorCode;
import
org.h2.message.Message
;
import
org.h2.table.Table
;
public
abstract
class
RightOwner
extends
DbObject
{
public
abstract
class
RightOwner
extends
DbObject
Base
{
// key: role; value: right
private
HashMap
grantedRoles
;
...
...
h2/src/main/org/h2/engine/Setting.java
浏览文件 @
79ba7f42
...
...
@@ -10,7 +10,7 @@ import org.h2.message.Message;
import
org.h2.message.Trace
;
import
org.h2.table.Table
;
public
class
Setting
extends
DbObject
{
public
class
Setting
extends
DbObject
Base
{
private
int
intValue
;
private
String
stringValue
;
...
...
h2/src/main/org/h2/engine/UserDataType.java
浏览文件 @
79ba7f42
...
...
@@ -11,7 +11,7 @@ import org.h2.message.Trace;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
public
class
UserDataType
extends
DbObject
{
public
class
UserDataType
extends
DbObject
Base
{
private
Column
column
;
...
...
h2/src/main/org/h2/expression/Aggregate.java
浏览文件 @
79ba7f42
...
...
@@ -16,6 +16,7 @@ import org.h2.engine.Database;
import
org.h2.engine.Session
;
import
org.h2.index.Index
;
import
org.h2.message.Message
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
...
...
@@ -160,7 +161,8 @@ public class Aggregate extends Expression {
case
MAX:
boolean
first
=
type
==
MIN
;
Index
index
=
getColumnIndex
(
first
);
Value
v
=
index
.
findFirstOrLast
(
session
,
first
);
SearchRow
row
=
index
.
findFirstOrLast
(
session
,
first
);
Value
v
=
row
.
getValue
(
index
.
getColumns
()[
0
].
getColumnId
());
return
v
;
default
:
throw
Message
.
getInternalError
(
"type="
+
type
);
...
...
h2/src/main/org/h2/index/BaseIndex.java
0 → 100644
浏览文件 @
79ba7f42
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
index
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Session
;
import
org.h2.message.Message
;
import
org.h2.message.Trace
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.schema.SchemaObjectBase
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
/**
* @author Thomas
*/
public
abstract
class
BaseIndex
extends
SchemaObjectBase
implements
Index
{
protected
Column
[]
columns
;
protected
int
[]
columnIndex
;
protected
Table
table
;
protected
IndexType
indexType
;
protected
long
rowCount
;
public
BaseIndex
(
Table
table
,
int
id
,
String
name
,
Column
[]
columns
,
IndexType
indexType
)
{
super
(
table
.
getSchema
(),
id
,
name
,
Trace
.
INDEX
);
this
.
indexType
=
indexType
;
this
.
table
=
table
;
if
(
columns
!=
null
)
{
this
.
columns
=
columns
;
columnIndex
=
new
int
[
columns
.
length
];
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
columnIndex
[
i
]
=
columns
[
i
].
getColumnId
();
}
}
}
public
String
getDropSQL
()
{
return
null
;
}
public
SQLException
getDuplicateKeyException
()
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
getName
());
buff
.
append
(
" "
);
buff
.
append
(
" ON "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
"("
);
buff
.
append
(
getColumnListSQL
());
buff
.
append
(
")"
);
return
Message
.
getSQLException
(
ErrorCode
.
DUPLICATE_KEY_1
,
buff
.
toString
());
}
public
String
getPlanSQL
()
{
return
getSQL
();
}
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
table
.
removeIndex
(
this
);
remove
(
session
);
}
public
abstract
void
close
(
Session
session
)
throws
SQLException
;
public
abstract
void
add
(
Session
session
,
Row
row
)
throws
SQLException
;
public
abstract
void
remove
(
Session
session
,
Row
row
)
throws
SQLException
;
public
abstract
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
throws
SQLException
;
public
abstract
double
getCost
(
Session
session
,
int
[]
masks
)
throws
SQLException
;
public
abstract
void
remove
(
Session
session
)
throws
SQLException
;
public
abstract
void
truncate
(
Session
session
)
throws
SQLException
;
public
abstract
boolean
canGetFirstOrLast
(
boolean
first
);
public
abstract
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
;
public
abstract
boolean
needRebuild
();
public
long
getRowCount
(
Session
session
)
{
return
rowCount
;
}
public
int
getLookupCost
(
long
rowCount
)
{
return
2
;
}
public
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
)
throws
SQLException
{
rowCount
+=
Constants
.
COST_ROW_OFFSET
;
long
cost
=
rowCount
;
int
totalSelectivity
=
0
;
for
(
int
i
=
0
;
masks
!=
null
&&
i
<
columns
.
length
;
i
++)
{
Column
column
=
columns
[
i
];
int
index
=
column
.
getColumnId
();
int
mask
=
masks
[
index
];
if
((
mask
&
IndexCondition
.
EQUALITY
)
==
IndexCondition
.
EQUALITY
)
{
if
(
i
==
columns
.
length
-
1
&&
getIndexType
().
isUnique
())
{
cost
=
getLookupCost
(
rowCount
)
+
1
;
break
;
}
totalSelectivity
=
100
-
((
100
-
totalSelectivity
)
*
(
100
-
column
.
getSelectivity
())
/
100
);
long
distinctRows
=
rowCount
*
totalSelectivity
/
100
;
if
(
distinctRows
<=
0
)
{
distinctRows
=
1
;
}
long
rowsSelected
=
rowCount
/
distinctRows
;
if
(
rowsSelected
<
1
)
{
rowsSelected
=
1
;
}
cost
=
getLookupCost
(
rowCount
)
+
rowsSelected
;
}
else
if
((
mask
&
IndexCondition
.
RANGE
)
==
IndexCondition
.
RANGE
)
{
cost
=
getLookupCost
(
rowCount
)
+
rowCount
/
4
;
break
;
}
else
if
((
mask
&
IndexCondition
.
START
)
==
IndexCondition
.
START
)
{
cost
=
getLookupCost
(
rowCount
)
+
rowCount
/
3
;
break
;
}
else
if
((
mask
&
IndexCondition
.
END
)
==
IndexCondition
.
END
)
{
cost
=
rowCount
/
3
;
break
;
}
else
{
break
;
}
}
return
cost
;
}
public
int
compareRows
(
SearchRow
rowData
,
SearchRow
compare
)
throws
SQLException
{
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
int
index
=
columnIndex
[
i
];
Value
v
=
compare
.
getValue
(
index
);
if
(
v
==
null
)
{
// can't compare further
return
0
;
}
int
c
=
compareValues
(
rowData
.
getValue
(
index
),
v
);
if
(
c
!=
0
)
{
return
c
;
}
}
return
0
;
}
public
boolean
isNull
(
Row
newRow
)
{
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
int
index
=
columnIndex
[
i
];
Value
v
=
newRow
.
getValue
(
index
);
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
true
;
}
}
return
false
;
}
public
int
compareKeys
(
SearchRow
rowData
,
SearchRow
compare
)
{
int
k1
=
rowData
.
getPos
();
int
k2
=
compare
.
getPos
();
if
(
k1
==
k2
)
{
return
0
;
}
return
k1
>
k2
?
1
:
-
1
;
}
private
int
compareValues
(
Value
v1
,
Value
v2
)
throws
SQLException
{
if
(
v1
==
null
)
{
if
(
v2
==
null
)
{
return
0
;
}
return
1
;
}
if
(
v2
==
null
)
{
return
-
1
;
}
return
database
.
compareTypeSave
(
v1
,
v2
);
}
public
int
getColumnIndex
(
Column
col
)
{
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
columns
[
i
]
==
col
)
{
return
i
;
}
}
return
-
1
;
}
public
String
getColumnListSQL
()
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
if
(
i
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
columns
[
i
].
getSQL
());
}
return
buff
.
toString
();
}
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"CREATE "
);
buff
.
append
(
indexType
.
getSQL
());
if
(!
indexType
.
isPrimaryKey
())
{
buff
.
append
(
' '
);
buff
.
append
(
quotedName
);
}
buff
.
append
(
" ON "
);
buff
.
append
(
table
.
getSQL
());
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
);
buff
.
append
(
StringUtils
.
quoteStringSQL
(
comment
));
}
buff
.
append
(
"("
);
buff
.
append
(
getColumnListSQL
());
buff
.
append
(
")"
);
return
buff
.
toString
();
}
public
String
getCreateSQL
()
{
return
getCreateSQLForCopy
(
table
,
getSQL
());
}
public
Column
[]
getColumns
()
{
return
columns
;
}
public
IndexType
getIndexType
()
{
return
indexType
;
}
public
int
getType
()
{
return
DbObject
.
INDEX
;
}
public
Table
getTable
()
{
return
table
;
}
public
void
commit
(
Row
row
)
throws
SQLException
{
}
}
h2/src/main/org/h2/index/BtreeCursor.java
浏览文件 @
79ba7f42
...
...
@@ -87,17 +87,6 @@ public class BtreeCursor implements Cursor {
}
}
}
if
(
SysProperties
.
MVCC
)
{
if
(
currentSearchRow
!=
null
)
{
while
(
true
)
{
Row
r
=
get
();
int
sessionId
=
r
.
getSessionId
();
if
(
sessionId
==
0
||
sessionId
==
session
.
getId
())
{
break
;
}
}
}
}
return
currentSearchRow
!=
null
;
}
...
...
h2/src/main/org/h2/index/BtreeIndex.java
浏览文件 @
79ba7f42
...
...
@@ -26,7 +26,7 @@ import org.h2.value.ValueNull;
/**
* @author Thomas
*/
public
class
BtreeIndex
extends
Index
implements
RecordReader
{
public
class
BtreeIndex
extends
Base
Index
implements
RecordReader
{
// TODO index / btree: tune page size
// final static int MAX_PAGE_SIZE = 256;
...
...
@@ -164,17 +164,12 @@ public class BtreeIndex extends Index implements RecordReader {
public
void
remove
(
Session
session
,
Row
row
)
throws
SQLException
{
setChanged
(
session
);
if
(
SysProperties
.
MVCC
)
{
if
(
rowCount
==
1
)
{
// TODO performance: maybe improve truncate performance in this case
truncate
(
session
);
}
else
{
root
.
remove
(
session
,
row
,
0
);
rowCount
--;
}
else
{
if
(
rowCount
==
1
)
{
// TODO performance: maybe improve truncate performance in this case
truncate
(
session
);
}
else
{
root
.
remove
(
session
,
row
,
0
);
rowCount
--;
}
}
}
...
...
@@ -188,7 +183,7 @@ public class BtreeIndex extends Index implements RecordReader {
return
cursor
;
}
else
{
BtreeCursor
cursor
=
new
BtreeCursor
(
session
,
this
,
last
);
if
(!
root
.
findFirst
(
cursor
,
first
))
{
if
(
getRowCount
(
session
)==
0
||
!
root
.
findFirst
(
cursor
,
first
))
{
cursor
.
setCurrentRow
(
null
);
}
return
cursor
;
...
...
@@ -290,24 +285,20 @@ public class BtreeIndex extends Index implements RecordReader {
return
true
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
if
(
first
)
{
// TODO optimization: this loops through NULL
value
s
// TODO optimization: this loops through NULL
element
s
Cursor
cursor
=
find
(
session
,
null
,
null
);
while
(
cursor
.
next
())
{
Value
v
=
cursor
.
get
().
getValue
(
columnIndex
[
0
]);
SearchRow
row
=
cursor
.
getSearchRow
();
Value
v
=
row
.
getValue
(
columnIndex
[
0
]);
if
(
v
!=
ValueNull
.
INSTANCE
)
{
return
v
;
return
row
;
}
}
return
ValueNull
.
INSTANCE
;
return
null
;
}
else
{
SearchRow
row
=
root
.
getLast
(
session
);
if
(
row
!=
null
)
{
Value
v
=
row
.
getValue
(
columnIndex
[
0
]);
return
v
;
}
return
ValueNull
.
INSTANCE
;
return
root
.
getLast
(
session
);
}
}
...
...
h2/src/main/org/h2/index/BtreeLeaf.java
浏览文件 @
79ba7f42
...
...
@@ -60,18 +60,7 @@ public class BtreeLeaf extends BtreePage {
if
(
comp
==
0
)
{
if
(
index
.
indexType
.
isUnique
())
{
if
(!
index
.
isNull
(
newRow
))
{
if
(
SysProperties
.
MVCC
)
{
int
todoMVCC
;
// currently, throw a duplicate row exception even if another transaction
// updated or deleted the same row and did not yet commit - PostgreSQL waits but in most cases transactions are committed
if
(
row
.
getDeleted
()
&&
row
.
getSessionId
()
==
session
.
getId
())
{
// ignore: deleted
}
else
{
throw
index
.
getDuplicateKeyException
();
}
}
else
{
throw
index
.
getDuplicateKeyException
();
}
throw
index
.
getDuplicateKeyException
();
}
}
comp
=
index
.
compareKeys
(
row
,
newRow
);
...
...
@@ -262,9 +251,7 @@ public class BtreeLeaf extends BtreePage {
int
size
=
2
+
dummy
.
getIntLen
()
*
(
len
+
1
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
SearchRow
row
=
(
SearchRow
)
pageData
.
get
(
i
);
if
(!
row
.
getDeleted
())
{
size
+=
getRowSize
(
dummy
,
row
);
}
size
+=
getRowSize
(
dummy
,
row
);
}
size
+=
index
.
getRecordOverhead
();
cachedRealByteCount
=
size
;
...
...
h2/src/main/org/h2/index/BtreeNode.java
浏览文件 @
79ba7f42
...
...
@@ -60,7 +60,6 @@ public class BtreeNode extends BtreePage {
SearchRow
r
=
(
SearchRow
)
pageData
.
get
(
i
);
if
(
r
==
null
)
{
int
p
=
pageChildren
.
get
(
i
+
1
);
// MVCC: get the committed data
Session
session
=
index
.
getDatabase
().
getSystemSession
();
BtreePage
page
=
index
.
getPage
(
session
,
p
);
r
=
page
.
getFirst
(
session
);
...
...
h2/src/main/org/h2/index/FunctionIndex.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
index
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.expression.FunctionCall
;
import
org.h2.message.Message
;
...
...
@@ -14,9 +13,8 @@ import org.h2.result.Row;
import
org.h2.result.SearchRow
;
import
org.h2.table.Column
;
import
org.h2.table.FunctionTable
;
import
org.h2.value.Value
;
public
class
FunctionIndex
extends
Index
{
public
class
FunctionIndex
extends
Base
Index
{
private
FunctionTable
functionTable
;
private
LocalResult
result
;
...
...
@@ -73,7 +71,7 @@ public class FunctionIndex extends Index {
return
false
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/index/HashIndex.java
浏览文件 @
79ba7f42
...
...
@@ -21,7 +21,7 @@ import org.h2.value.ValueArray;
/**
* @author Thomas
*/
public
class
HashIndex
extends
Index
{
public
class
HashIndex
extends
Base
Index
{
private
ValueHashMap
rows
;
private
IntIntHashMap
intMap
;
...
...
@@ -145,7 +145,7 @@ public class HashIndex extends Index {
return
false
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/index/LinearHashIndex.java
浏览文件 @
79ba7f42
...
...
@@ -27,7 +27,7 @@ import org.h2.value.ValueArray;
/**
* @author Thomas
*/
public
class
LinearHashIndex
extends
Index
implements
RecordReader
{
public
class
LinearHashIndex
extends
Base
Index
implements
RecordReader
{
// TODO index / linear hash: tune page size
// private static final int MAX_PAGE_SIZE = 256;
...
...
@@ -535,7 +535,7 @@ public class LinearHashIndex extends Index implements RecordReader {
return
false
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
79ba7f42
...
...
@@ -23,7 +23,7 @@ import org.h2.value.ValueNull;
* @author Thomas
*/
public
class
LinkedIndex
extends
Index
{
public
class
LinkedIndex
extends
Base
Index
{
private
TableLink
link
;
private
String
originalTable
;
...
...
@@ -161,7 +161,7 @@ public class LinkedIndex extends Index {
return
false
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
// TODO optimization: could get the first or last value (in any case; maybe not optimized)
throw
Message
.
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/index/MetaIndex.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
index
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.message.Message
;
import
org.h2.result.Row
;
...
...
@@ -13,14 +12,13 @@ import org.h2.result.SearchRow;
import
org.h2.table.Column
;
import
org.h2.table.MetaTable
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.Value
;
/**
* @author Thomas
*/
public
class
MetaIndex
extends
Index
{
public
class
MetaIndex
extends
Base
Index
{
private
MetaTable
meta
;
private
boolean
scan
;
...
...
@@ -87,7 +85,7 @@ public class MetaIndex extends Index {
return
false
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/index/MultiVersionCursor.java
0 → 100644
浏览文件 @
79ba7f42
package
org
.
h2
.
index
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
public
class
MultiVersionCursor
implements
Cursor
{
private
final
MultiVersionIndex
index
;
private
final
Session
session
;
private
final
Cursor
base
,
delta
;
private
boolean
onBase
;
private
SearchRow
current
;
MultiVersionCursor
(
Session
session
,
MultiVersionIndex
index
,
Cursor
base
,
Cursor
delta
)
throws
SQLException
{
this
.
session
=
session
;
this
.
index
=
index
;
this
.
base
=
base
;
this
.
delta
=
delta
;
boolean
b
=
base
.
next
();
boolean
d
=
delta
.
next
();
}
public
Row
get
()
throws
SQLException
{
return
onBase
?
base
.
get
()
:
delta
.
get
();
}
public
int
getPos
()
{
return
onBase
?
base
.
getPos
()
:
delta
.
getPos
();
}
public
SearchRow
getSearchRow
()
throws
SQLException
{
return
onBase
?
base
.
getSearchRow
()
:
delta
.
getSearchRow
();
}
public
boolean
next
()
throws
SQLException
{
return
false
;
}
}
h2/src/main/org/h2/index/MultiVersionIndex.java
0 → 100644
浏览文件 @
79ba7f42
package
org
.
h2
.
index
;
import
java.sql.SQLException
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.message.Message
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.schema.Schema
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.TableData
;
import
org.h2.util.ObjectArray
;
public
class
MultiVersionIndex
implements
Index
{
private
Index
base
;
private
TreeIndex
delta
;
public
MultiVersionIndex
(
Index
base
,
TableData
table
)
throws
SQLException
{
this
.
base
=
base
;
IndexType
deltaIndexType
=
IndexType
.
createNonUnique
(
false
);
this
.
delta
=
new
TreeIndex
(
table
,
-
1
,
"DELTA"
,
base
.
getColumns
(),
deltaIndexType
);
}
public
void
add
(
Session
session
,
Row
row
)
throws
SQLException
{
base
.
add
(
session
,
row
);
delta
.
add
(
session
,
row
);
}
public
void
close
(
Session
session
)
throws
SQLException
{
base
.
close
(
session
);
}
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
throws
SQLException
{
Cursor
baseCursor
=
base
.
find
(
session
,
first
,
last
);
Cursor
deltaCursor
=
delta
.
find
(
session
,
first
,
last
);
return
new
MultiVersionCursor
(
session
,
this
,
baseCursor
,
deltaCursor
);
}
public
boolean
canGetFirstOrLast
(
boolean
first
)
{
int
todoMVCC_Min_Max_Optimization
;
return
false
;
}
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
int
todoMVCC_Min_Max_Optimization
;
throw
Message
.
getUnsupportedException
();
}
public
double
getCost
(
Session
session
,
int
[]
masks
)
throws
SQLException
{
return
base
.
getCost
(
session
,
masks
);
}
public
boolean
needRebuild
()
{
return
base
.
needRebuild
();
}
public
void
remove
(
Session
session
,
Row
row
)
throws
SQLException
{
base
.
remove
(
session
,
row
);
delta
.
add
(
session
,
row
);
}
public
void
remove
(
Session
session
)
throws
SQLException
{
base
.
remove
(
session
);
}
public
void
truncate
(
Session
session
)
throws
SQLException
{
int
todoLockingRequired
;
base
.
truncate
(
session
);
}
public
void
commit
(
Row
row
)
throws
SQLException
{
delta
.
remove
(
null
,
row
);
}
public
int
compareKeys
(
SearchRow
rowData
,
SearchRow
compare
)
{
return
base
.
compareKeys
(
rowData
,
compare
);
}
public
int
compareRows
(
SearchRow
rowData
,
SearchRow
compare
)
throws
SQLException
{
return
base
.
compareRows
(
rowData
,
compare
);
}
public
int
getColumnIndex
(
Column
col
)
{
return
base
.
getColumnIndex
(
col
);
}
public
String
getColumnListSQL
()
{
return
base
.
getColumnListSQL
();
}
public
Column
[]
getColumns
()
{
return
base
.
getColumns
();
}
public
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
)
throws
SQLException
{
return
base
.
getCostRangeIndex
(
masks
,
rowCount
);
}
public
String
getCreateSQL
()
{
return
base
.
getCreateSQL
();
}
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
return
base
.
getCreateSQLForCopy
(
table
,
quotedName
);
}
public
String
getDropSQL
()
{
return
base
.
getDropSQL
();
}
public
SQLException
getDuplicateKeyException
()
{
return
base
.
getDuplicateKeyException
();
}
public
IndexType
getIndexType
()
{
return
base
.
getIndexType
();
}
public
int
getLookupCost
(
long
rowCount
)
{
return
base
.
getLookupCost
(
rowCount
);
}
public
String
getPlanSQL
()
{
return
base
.
getPlanSQL
();
}
public
long
getRowCount
(
Session
session
)
{
return
base
.
getRowCount
(
session
);
}
public
Table
getTable
()
{
return
base
.
getTable
();
}
public
int
getType
()
{
return
base
.
getType
();
}
public
boolean
isNull
(
Row
newRow
)
{
return
base
.
isNull
(
newRow
);
}
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
base
.
removeChildrenAndResources
(
session
);
}
public
String
getSQL
()
{
return
base
.
getSQL
();
}
public
Schema
getSchema
()
{
return
base
.
getSchema
();
}
public
void
checkRename
()
throws
SQLException
{
base
.
checkRename
();
}
public
ObjectArray
getChildren
()
{
return
base
.
getChildren
();
}
public
String
getComment
()
{
return
base
.
getComment
();
}
public
Database
getDatabase
()
{
return
base
.
getDatabase
();
}
public
int
getHeadPos
()
{
return
base
.
getHeadPos
();
}
public
int
getId
()
{
return
base
.
getId
();
}
public
long
getModificationId
()
{
return
base
.
getModificationId
();
}
public
String
getName
()
{
return
base
.
getName
();
}
public
boolean
getTemporary
()
{
return
base
.
getTemporary
();
}
public
void
rename
(
String
newName
)
throws
SQLException
{
base
.
rename
(
newName
);
}
public
void
setComment
(
String
comment
)
{
base
.
setComment
(
comment
);
}
public
void
setModified
()
{
base
.
setModified
();
}
public
void
setTemporary
(
boolean
temporary
)
{
base
.
setTemporary
(
temporary
);
}
}
h2/src/main/org/h2/index/RangeIndex.java
浏览文件 @
79ba7f42
...
...
@@ -15,7 +15,7 @@ import org.h2.table.RangeTable;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
public
class
RangeIndex
extends
Index
{
public
class
RangeIndex
extends
Base
Index
{
private
long
min
,
max
;
...
...
@@ -70,8 +70,8 @@ public class RangeIndex extends Index {
return
true
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
return
ValueLong
.
get
(
first
?
min
:
max
);
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
return
new
Row
(
new
Value
[]{
ValueLong
.
get
(
first
?
min
:
max
)},
0
);
}
}
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
79ba7f42
...
...
@@ -23,7 +23,7 @@ import org.h2.value.ValueLob;
/**
* @author Thomas
*/
public
class
ScanIndex
extends
Index
{
public
class
ScanIndex
extends
Base
Index
{
private
int
firstFree
=
-
1
;
private
ObjectArray
rows
=
new
ObjectArray
();
private
Storage
storage
;
...
...
@@ -193,7 +193,7 @@ public class ScanIndex extends Index {
return
false
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/index/TreeIndex.java
浏览文件 @
79ba7f42
...
...
@@ -17,7 +17,7 @@ import org.h2.value.Value;
import
org.h2.value.ValueNull
;
public
class
TreeIndex
extends
Index
{
public
class
TreeIndex
extends
Base
Index
{
private
TreeNode
root
;
private
TableData
tableData
;
...
...
@@ -340,17 +340,18 @@ public class TreeIndex extends Index {
return
true
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
if
(
first
)
{
// TODO optimization: this loops through NULL values
Cursor
cursor
=
find
(
session
,
null
,
null
);
while
(
cursor
.
next
())
{
Value
v
=
cursor
.
get
().
getValue
(
columnIndex
[
0
]);
SearchRow
row
=
cursor
.
getSearchRow
();
Value
v
=
row
.
getValue
(
columnIndex
[
0
]);
if
(
v
!=
ValueNull
.
INSTANCE
)
{
return
v
;
return
row
;
}
}
return
ValueNull
.
INSTANCE
;
return
null
;
}
else
{
TreeNode
x
=
root
,
n
;
while
(
x
!=
null
)
{
...
...
@@ -361,10 +362,9 @@ public class TreeIndex extends Index {
x
=
n
;
}
if
(
x
!=
null
)
{
Value
v
=
x
.
row
.
getValue
(
columnIndex
[
0
]);
return
v
;
return
x
.
row
;
}
return
ValueNull
.
INSTANCE
;
return
null
;
}
}
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
index
;
import
java.sql.SQLException
;
import
org.h2.command.dml.Query
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Session
;
...
...
@@ -18,11 +17,11 @@ import org.h2.result.SearchRow;
import
org.h2.table.Column
;
import
org.h2.table.TableView
;
import
org.h2.util.IntArray
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.value.Value
;
public
class
ViewIndex
extends
Index
{
public
class
ViewIndex
extends
Base
Index
{
private
String
querySQL
;
private
ObjectArray
originalParameters
;
...
...
@@ -232,7 +231,7 @@ public class ViewIndex extends Index {
return
false
;
}
public
Value
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
public
SearchRow
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
throw
Message
.
getUnsupportedException
();
}
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
79ba7f42
...
...
@@ -315,7 +315,7 @@ The selectivity can be set manually with ALTER TABLE ALTER COLUMN SELECTIVITY.
The manual values are overwritten by this statement.
The selectivity is available in the INFORMATION_SCHEMA.COLUMNS table.
","
ANALYZE
TOP
1000
ANALYZE
SAMPLE_SIZE
1000
"
"Commands (DDL)","COMMENT","
...
...
h2/src/main/org/h2/result/SearchRow.java
浏览文件 @
79ba7f42
...
...
@@ -4,7 +4,6 @@
*/
package
org
.
h2
.
result
;
import
org.h2.engine.Session
;
import
org.h2.value.Value
;
public
interface
SearchRow
{
...
...
@@ -14,8 +13,5 @@ public interface SearchRow {
int
getColumnCount
();
void
setValue
(
int
idx
,
Value
v
);
void
setPos
(
int
pos
);
void
setDeleted
(
Session
session
,
boolean
deleted
);
int
getSessionId
();
boolean
getDeleted
();
}
h2/src/main/org/h2/result/SimpleRow.java
浏览文件 @
79ba7f42
...
...
@@ -4,15 +4,12 @@
*/
package
org
.
h2
.
result
;
import
org.h2.engine.Session
;
import
org.h2.value.Value
;
public
class
SimpleRow
implements
SearchRow
{
private
int
pos
;
private
Value
[]
data
;
private
int
sessionId
;
private
boolean
deleted
;
public
SimpleRow
(
Value
[]
data
)
{
this
.
data
=
data
;
...
...
@@ -38,18 +35,4 @@ public class SimpleRow implements SearchRow {
return
data
[
i
];
}
public
boolean
getDeleted
()
{
return
deleted
;
}
public
void
setDeleted
(
Session
session
,
boolean
deleted
)
{
this
.
sessionId
=
session
.
getId
();
this
.
deleted
=
deleted
;
}
public
int
getSessionId
()
{
int
testing
;
return
sessionId
;
}
}
h2/src/main/org/h2/result/SimpleRowValue.java
浏览文件 @
79ba7f42
...
...
@@ -4,7 +4,6 @@
*/
package
org
.
h2
.
result
;
import
org.h2.engine.Session
;
import
org.h2.value.Value
;
public
class
SimpleRowValue
implements
SearchRow
{
...
...
@@ -13,8 +12,6 @@ public class SimpleRowValue implements SearchRow {
private
int
index
;
private
int
virtualColumnCount
;
private
Value
data
;
private
int
sessionId
;
private
boolean
deleted
;
public
SimpleRowValue
(
int
columnCount
)
{
this
.
virtualColumnCount
=
columnCount
;
...
...
@@ -37,19 +34,5 @@ public class SimpleRowValue implements SearchRow {
index
=
idx
;
data
=
v
;
}
public
boolean
getDeleted
()
{
return
deleted
;
}
public
void
setDeleted
(
Session
session
,
boolean
deleted
)
{
this
.
sessionId
=
session
.
getId
();
this
.
deleted
=
deleted
;
}
public
int
getSessionId
()
{
int
testing
;
return
sessionId
;
}
}
h2/src/main/org/h2/schema/Constant.java
浏览文件 @
79ba7f42
...
...
@@ -14,7 +14,7 @@ import org.h2.message.Trace;
import
org.h2.table.Table
;
import
org.h2.value.Value
;
public
class
Constant
extends
SchemaObject
{
public
class
Constant
extends
SchemaObject
Base
{
private
Value
value
;
private
ValueExpression
expression
;
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
79ba7f42
...
...
@@ -13,8 +13,10 @@ import org.h2.constraint.Constraint;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.DbObjectBase
;
import
org.h2.engine.Session
;
import
org.h2.engine.User
;
import
org.h2.index.BaseIndex
;
import
org.h2.index.Index
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.message.Message
;
...
...
@@ -24,7 +26,7 @@ import org.h2.table.TableData;
import
org.h2.table.TableLink
;
import
org.h2.util.ObjectArray
;
public
class
Schema
extends
DbObject
{
public
class
Schema
extends
DbObject
Base
{
private
User
owner
;
private
boolean
system
;
...
...
h2/src/main/org/h2/schema/SchemaObjectBase.java
0 → 100644
浏览文件 @
79ba7f42
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
schema
;
import
org.h2.engine.DbObjectBase
;
public
abstract
class
SchemaObjectBase
extends
DbObjectBase
implements
SchemaObject
{
private
Schema
schema
;
protected
SchemaObjectBase
(
Schema
schema
,
int
id
,
String
name
,
String
traceModule
)
{
super
(
schema
.
getDatabase
(),
id
,
name
,
traceModule
);
this
.
schema
=
schema
;
}
public
Schema
getSchema
()
{
return
schema
;
}
public
String
getSQL
()
{
return
schema
.
getSQL
()
+
"."
+
super
.
getSQL
();
}
}
h2/src/main/org/h2/schema/Sequence.java
浏览文件 @
79ba7f42
...
...
@@ -14,7 +14,7 @@ import org.h2.message.Message;
import
org.h2.message.Trace
;
import
org.h2.table.Table
;
public
class
Sequence
extends
SchemaObject
{
public
class
Sequence
extends
SchemaObject
Base
{
private
static
final
int
BLOCK_INCREMENT
=
32
;
private
long
value
=
1
;
private
long
valueWithMargin
;
...
...
h2/src/main/org/h2/schema/TriggerObject.java
浏览文件 @
79ba7f42
...
...
@@ -23,7 +23,7 @@ import org.h2.value.Value;
* @author Thomas
*/
public
class
TriggerObject
extends
SchemaObject
{
public
class
TriggerObject
extends
SchemaObject
Base
{
public
static
final
int
INSERT
=
1
,
UPDATE
=
2
,
DELETE
=
4
;
public
static
final
int
DEFAULT_QUEUE_SIZE
=
1024
;
...
...
h2/src/main/org/h2/store/UndoLogRecord.java
浏览文件 @
79ba7f42
...
...
@@ -15,6 +15,7 @@ import org.h2.index.Index;
import
org.h2.message.Message
;
import
org.h2.result.Row
;
import
org.h2.table.Table
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.Value
;
/**
...
...
@@ -141,7 +142,12 @@ public class UndoLogRecord {
return
table
;
}
public
void
commit
()
{
public
void
commit
()
throws
SQLException
{
ObjectArray
list
=
table
.
getIndexes
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Index
index
=
(
Index
)
list
.
get
(
i
);
index
.
commit
(
row
);
}
row
.
commit
();
}
}
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
79ba7f42
...
...
@@ -7,7 +7,6 @@ package org.h2.table;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
79ba7f42
...
...
@@ -14,7 +14,6 @@ import java.sql.SQLException;
import
java.text.Collator
;
import
java.util.Locale
;
import
java.util.Properties
;
import
org.h2.constant.SysProperties
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintCheck
;
...
...
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
79ba7f42
...
...
@@ -5,7 +5,6 @@
package
org
.
h2
.
table
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
79ba7f42
...
...
@@ -6,7 +6,6 @@ package org.h2.table;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
org.h2.command.Prepared
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constraint.Constraint
;
...
...
@@ -23,7 +22,7 @@ import org.h2.result.SearchRow;
import
org.h2.result.SimpleRow
;
import
org.h2.result.SimpleRowValue
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.SchemaObject
Base
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.TriggerObject
;
import
org.h2.store.UndoLogRecord
;
...
...
@@ -36,7 +35,7 @@ import org.h2.value.ValueNull;
* @author Thomas
*/
public
abstract
class
Table
extends
SchemaObject
{
public
abstract
class
Table
extends
SchemaObject
Base
{
public
static
final
int
TYPE_CACHED
=
0
,
TYPE_MEMORY
=
1
;
...
...
@@ -317,7 +316,7 @@ public abstract class Table extends SchemaObject {
ObjectArray
indexes
=
getIndexes
();
if
(
indexes
!=
null
)
{
remove
(
indexes
,
index
);
if
(
index
.
indexType
.
isPrimaryKey
())
{
if
(
index
.
getIndexType
()
.
isPrimaryKey
())
{
Column
[]
cols
=
index
.
getColumns
();
for
(
int
i
=
0
;
i
<
cols
.
length
;
i
++)
{
cols
[
i
].
setPrimaryKey
(
false
);
...
...
h2/src/main/org/h2/table/TableData.java
浏览文件 @
79ba7f42
...
...
@@ -7,7 +7,6 @@ package org.h2.table;
import
java.sql.SQLException
;
import
java.util.Comparator
;
import
java.util.HashSet
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
...
...
@@ -22,6 +21,7 @@ import org.h2.index.HashIndex;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
import
org.h2.index.LinearHashIndex
;
import
org.h2.index.MultiVersionIndex
;
import
org.h2.index.ScanIndex
;
import
org.h2.index.TreeIndex
;
import
org.h2.message.Message
;
...
...
@@ -83,7 +83,7 @@ public class TableData extends Table implements RecordReader {
Index
index
=
(
Index
)
indexes
.
get
(
i
);
index
.
add
(
session
,
row
);
if
(
SysProperties
.
CHECK
)
{
long
rc
=
index
.
getRowCount
();
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
+
1
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
+
1
)+
" got "
+
rc
);
}
...
...
@@ -96,7 +96,7 @@ public class TableData extends Table implements RecordReader {
Index
index
=
(
Index
)
indexes
.
get
(
i
);
index
.
remove
(
session
,
row
);
if
(
SysProperties
.
CHECK
)
{
long
rc
=
index
.
getRowCount
();
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
)+
" got "
+
rc
);
}
...
...
@@ -156,10 +156,13 @@ public class TableData extends Table implements RecordReader {
index
=
new
TreeIndex
(
this
,
indexId
,
indexName
,
cols
,
indexType
);
}
}
if
(
SysProperties
.
MVCC
)
{
index
=
new
MultiVersionIndex
(
index
,
this
);
}
if
(
index
.
needRebuild
()
&&
rowCount
>
0
)
{
try
{
Index
scan
=
getScanIndex
(
session
);
long
remaining
=
scan
.
getRowCount
();
long
remaining
=
scan
.
getRowCount
(
session
);
long
total
=
remaining
;
Cursor
cursor
=
scan
.
find
(
session
,
null
,
null
);
long
i
=
0
;
...
...
@@ -253,7 +256,7 @@ public class TableData extends Table implements RecordReader {
Index
index
=
(
Index
)
indexes
.
get
(
i
);
index
.
remove
(
session
,
row
);
if
(
SysProperties
.
CHECK
)
{
long
rc
=
index
.
getRowCount
();
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
-
1
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
-
1
)+
" got "
+
rc
);
}
...
...
@@ -268,7 +271,7 @@ public class TableData extends Table implements RecordReader {
Index
index
=
(
Index
)
indexes
.
get
(
i
);
index
.
truncate
(
session
);
if
(
SysProperties
.
CHECK
)
{
long
rc
=
index
.
getRowCount
();
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
0
)
{
throw
Message
.
getInternalError
(
"rowCount expected 0 got "
+
rc
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论