Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f8664648
提交
f8664648
authored
10月 20, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sorted insert optimization
上级
cad2f4bf
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
60 行增加
和
22 行删除
+60
-22
Parser.java
h2/src/main/org/h2/command/Parser.java
+14
-15
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+6
-0
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+23
-0
Select.java
h2/src/main/org/h2/command/dml/Select.java
+3
-6
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+3
-0
PageIndex.java
h2/src/main/org/h2/index/PageIndex.java
+10
-0
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+1
-1
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
f8664648
...
...
@@ -723,9 +723,7 @@ public class Parser {
}
}
while
(
readIf
(
","
));
read
(
")"
);
IndexColumn
[]
cols
=
new
IndexColumn
[
columns
.
size
()];
columns
.
toArray
(
cols
);
return
cols
;
return
columns
.
toArray
(
new
IndexColumn
[
columns
.
size
()]);
}
private
String
[]
parseColumnList
()
throws
SQLException
{
...
...
@@ -734,9 +732,7 @@ public class Parser {
String
columnName
=
readColumnIdentifier
();
columns
.
add
(
columnName
);
}
while
(
readIfMore
());
String
[]
cols
=
new
String
[
columns
.
size
()];
columns
.
toArray
(
cols
);
return
cols
;
return
columns
.
toArray
(
new
String
[
columns
.
size
()]);
}
private
Column
[]
parseColumnList
(
Table
table
)
throws
SQLException
{
...
...
@@ -751,9 +747,7 @@ public class Parser {
columns
.
add
(
column
);
}
while
(
readIfMore
());
}
Column
[]
cols
=
new
Column
[
columns
.
size
()];
columns
.
toArray
(
cols
);
return
cols
;
return
columns
.
toArray
(
new
Column
[
columns
.
size
()]);
}
private
boolean
readIfMore
()
throws
SQLException
{
...
...
@@ -872,9 +866,7 @@ public class Parser {
}
}
while
(
readIfMore
());
}
Expression
[]
expr
=
new
Expression
[
values
.
size
()];
values
.
toArray
(
expr
);
command
.
addRow
(
expr
);
command
.
addRow
(
values
.
toArray
(
new
Expression
[
values
.
size
()]));
}
while
(
readIf
(
","
));
}
else
{
command
.
setQuery
(
parseSelect
());
...
...
@@ -888,6 +880,9 @@ public class Parser {
read
(
"INTO"
);
Table
table
=
readTableOrView
();
command
.
setTable
(
table
);
if
(
readIf
(
"SORTED"
))
{
command
.
setSortedInsertMode
(
true
);
}
if
(
readIf
(
"("
))
{
if
(
isToken
(
"SELECT"
)
||
isToken
(
"FROM"
))
{
command
.
setQuery
(
parseSelect
());
...
...
@@ -914,9 +909,7 @@ public class Parser {
}
}
while
(
readIfMore
());
}
Expression
[]
expr
=
new
Expression
[
values
.
size
()];
values
.
toArray
(
expr
);
command
.
addRow
(
expr
);
command
.
addRow
(
values
.
toArray
(
new
Expression
[
values
.
size
()]));
}
while
(
readIf
(
","
));
}
else
{
command
.
setQuery
(
parseSelect
());
...
...
@@ -4635,6 +4628,9 @@ public class Parser {
command
.
setTableName
(
tableName
);
command
.
setComment
(
readCommentIf
());
if
(
readIf
(
"AS"
))
{
if
(
readIf
(
"SORTED"
))
{
command
.
setSortedInsertMode
(
true
);
}
command
.
setQuery
(
parseSelect
());
}
else
{
read
(
"("
);
...
...
@@ -4710,6 +4706,9 @@ public class Parser {
}
while
(
readIfMore
());
}
if
(
readIf
(
"AS"
))
{
if
(
readIf
(
"SORTED"
))
{
command
.
setSortedInsertMode
(
true
);
}
command
.
setQuery
(
parseSelect
());
}
}
...
...
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
f8664648
...
...
@@ -38,6 +38,7 @@ public class CreateTable extends SchemaCommand {
private
boolean
onCommitTruncate
;
private
Query
asQuery
;
private
String
comment
;
private
boolean
sortedInsertMode
;
public
CreateTable
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
...
...
@@ -166,6 +167,7 @@ public class CreateTable extends SchemaCommand {
session
.
setUndoLogEnabled
(
false
);
Insert
insert
=
null
;
insert
=
new
Insert
(
session
);
insert
.
setSortedInsertMode
(
sortedInsertMode
);
insert
.
setQuery
(
asQuery
);
insert
.
setTable
(
table
);
insert
.
prepare
();
...
...
@@ -258,4 +260,8 @@ public class CreateTable extends SchemaCommand {
data
.
persistData
=
persistData
;
}
public
void
setSortedInsertMode
(
boolean
sortedInsertMode
)
{
this
.
sortedInsertMode
=
sortedInsertMode
;
}
}
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
f8664648
...
...
@@ -11,10 +11,12 @@ import java.sql.SQLException;
import
org.h2.command.Command
;
import
org.h2.command.Prepared
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Parameter
;
import
org.h2.index.PageIndex
;
import
org.h2.log.UndoLogRecord
;
import
org.h2.message.Message
;
import
org.h2.result.LocalResult
;
...
...
@@ -35,6 +37,7 @@ public class Insert extends Prepared {
private
Column
[]
columns
;
private
ObjectArray
<
Expression
[]>
list
=
ObjectArray
.
newInstance
();
private
Query
query
;
private
boolean
sortedInsertMode
;
public
Insert
(
Session
session
)
{
super
(
session
);
...
...
@@ -69,6 +72,22 @@ public class Insert extends Prepared {
}
public
int
update
()
throws
SQLException
{
Database
db
=
session
.
getDatabase
();
PageIndex
index
=
null
;
if
(
sortedInsertMode
&&
db
.
isPageStoreEnabled
()
&&
db
.
isPersistent
())
{
index
=
(
PageIndex
)
table
.
getScanIndex
(
session
);
index
.
setSortedInsertMode
(
true
);
}
try
{
return
insertRows
();
}
finally
{
if
(
index
!=
null
)
{
index
.
setSortedInsertMode
(
false
);
}
}
}
private
int
insertRows
()
throws
SQLException
{
int
count
;
session
.
getUser
().
checkRight
(
table
,
Right
.
INSERT
);
setCurrentRowNumber
(
0
);
...
...
@@ -210,4 +229,8 @@ public class Insert extends Prepared {
return
null
;
}
public
void
setSortedInsertMode
(
boolean
sortedInsertMode
)
{
this
.
sortedInsertMode
=
sortedInsertMode
;
}
}
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
f8664648
...
...
@@ -398,8 +398,7 @@ public class Select extends Query {
}
sortColumns
.
add
(
exprCol
.
getColumn
());
}
Column
[]
sortCols
=
new
Column
[
sortColumns
.
size
()];
sortColumns
.
toArray
(
sortCols
);
Column
[]
sortCols
=
sortColumns
.
toArray
(
new
Column
[
sortColumns
.
size
()]);
int
[]
sortTypes
=
sort
.
getSortTypes
();
if
(
sortCols
.
length
==
0
)
{
// sort just on constants - can use scan index
...
...
@@ -792,8 +791,7 @@ public class Select extends Query {
}
private
double
preparePlan
()
throws
SQLException
{
TableFilter
[]
topArray
=
new
TableFilter
[
topFilters
.
size
()];
topFilters
.
toArray
(
topArray
);
TableFilter
[]
topArray
=
topFilters
.
toArray
(
new
TableFilter
[
topFilters
.
size
()]);
for
(
TableFilter
t
:
topArray
)
{
t
.
setFullCondition
(
condition
);
}
...
...
@@ -846,8 +844,7 @@ public class Select extends Query {
// can not use the field sqlStatement because the parameter
// indexes may be incorrect: ? may be in fact ?2 for a subquery
// but indexes may be set manually as well
Expression
[]
exprList
=
new
Expression
[
expressions
.
size
()];
expressions
.
toArray
(
exprList
);
Expression
[]
exprList
=
expressions
.
toArray
(
new
Expression
[
expressions
.
size
()]);
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT "
);
if
(
distinct
)
{
buff
.
append
(
"DISTINCT "
);
...
...
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
f8664648
...
...
@@ -156,6 +156,9 @@ public class PageDataLeaf extends PageData {
// required, otherwise the index doesn't work correctly
return
entryCount
/
2
;
}
if
(
index
.
isSortedInsertMode
())
{
return
x
<
2
?
1
:
x
>
entryCount
-
1
?
entryCount
-
1
:
x
;
}
// split near the insertion point to better fill pages
// split in half would be:
// return entryCount / 2;
...
...
h2/src/main/org/h2/index/PageIndex.java
浏览文件 @
f8664648
...
...
@@ -18,6 +18,8 @@ public abstract class PageIndex extends BaseIndex {
*/
protected
int
rootPageId
;
private
boolean
sortedInsertMode
;
public
int
getRootPageId
()
{
return
rootPageId
;
}
...
...
@@ -31,4 +33,12 @@ public abstract class PageIndex extends BaseIndex {
*/
public
abstract
void
writeRowCount
()
throws
SQLException
;
public
void
setSortedInsertMode
(
boolean
sortedInsertMode
)
{
this
.
sortedInsertMode
=
sortedInsertMode
;
}
boolean
isSortedInsertMode
()
{
return
sortedInsertMode
;
}
}
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
f8664648
...
...
@@ -72,7 +72,7 @@ import org.h2.value.ValueString;
* The format of page 1 and 2 is:
* <ul>
* <li>CRC32 of the remaining data: int (0-3)</li>
* <li>write counter (incremented
each time something is written
): long (4-11)</li>
* <li>write counter (incremented
on each write
): long (4-11)</li>
* <li>log trunk key: int (12-15)</li>
* <li>log trunk page (0 for none): int (16-19)</li>
* <li>log data page (0 for none): int (20-23)</li>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论