Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bfdaa836
提交
bfdaa836
authored
5月 21, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SYSTEM_RANGE now supports parameters
上级
39c4fb8f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
44 行增加
和
17 行删除
+44
-17
Parser.java
h2/src/main/org/h2/command/Parser.java
+12
-6
RangeIndex.java
h2/src/main/org/h2/index/RangeIndex.java
+6
-5
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+26
-6
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
bfdaa836
...
...
@@ -138,6 +138,7 @@ import org.h2.value.ValueBytes;
import
org.h2.value.ValueDate
;
import
org.h2.value.ValueDecimal
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueString
;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
...
...
@@ -858,7 +859,6 @@ public class Parser {
private
TableFilter
readTableFilter
(
boolean
fromOuter
)
throws
SQLException
{
Table
table
;
String
alias
=
null
;
Schema
mainSchema
=
database
.
getSchema
(
Constants
.
SCHEMA_MAIN
);
if
(
readIf
(
"("
))
{
if
(
isToken
(
"SELECT"
)
||
isToken
(
"FROM"
))
{
int
start
=
lastParseIndex
;
...
...
@@ -893,10 +893,11 @@ public class Parser {
}
else
{
String
tableName
=
readIdentifierWithSchema
(
null
);
if
(
readIf
(
"("
))
{
Schema
mainSchema
=
database
.
getSchema
(
Constants
.
SCHEMA_MAIN
);
if
(
tableName
.
equals
(
RangeTable
.
NAME
))
{
long
min
=
readLong
();
Expression
min
=
readExpression
();
read
(
","
);
long
max
=
readLong
();
Expression
max
=
readExpression
();
read
(
")"
);
table
=
new
RangeTable
(
mainSchema
,
min
,
max
);
}
else
{
...
...
@@ -907,7 +908,7 @@ public class Parser {
table
=
new
FunctionTable
(
mainSchema
,
session
,
(
FunctionCall
)
func
);
}
}
else
if
(
"DUAL"
.
equals
(
tableName
))
{
table
=
new
RangeTable
(
mainSchema
,
1
,
1
);
table
=
getDualTable
(
);
}
else
{
table
=
readTableOrView
(
tableName
);
}
...
...
@@ -1497,8 +1498,7 @@ public class Parser {
if
(!
readIf
(
"FROM"
))
{
// select without FROM: convert to SELECT ... FROM
// SYSTEM_RANGE(1,1)
Schema
main
=
database
.
findSchema
(
Constants
.
SCHEMA_MAIN
);
Table
dual
=
new
RangeTable
(
main
,
1
,
1
);
Table
dual
=
getDualTable
();
TableFilter
filter
=
new
TableFilter
(
session
,
dual
,
null
,
rightsChecked
,
currentSelect
);
command
.
addTableFilter
(
filter
,
true
);
}
else
{
...
...
@@ -1533,6 +1533,12 @@ public class Parser {
setSQL
(
command
,
"SELECT"
,
start
);
return
command
;
}
private
Table
getDualTable
()
throws
SQLException
{
Schema
main
=
database
.
findSchema
(
Constants
.
SCHEMA_MAIN
);
Expression
one
=
ValueExpression
.
get
(
ValueLong
.
get
(
1
));
return
new
RangeTable
(
main
,
one
,
one
);
}
private
void
setSQL
(
Prepared
command
,
String
start
,
int
startIndex
)
{
String
sql
=
originalSQL
.
substring
(
startIndex
,
lastParseIndex
).
trim
();
...
...
h2/src/main/org/h2/index/RangeIndex.java
浏览文件 @
bfdaa836
...
...
@@ -21,12 +21,11 @@ import org.h2.table.RangeTable;
*/
public
class
RangeIndex
extends
BaseIndex
{
private
long
min
,
max
;
private
RangeTable
table
;
public
RangeIndex
(
RangeTable
table
,
IndexColumn
[]
columns
,
long
min
,
long
max
)
{
public
RangeIndex
(
RangeTable
table
,
IndexColumn
[]
columns
)
{
initBaseIndex
(
table
,
0
,
"RANGE_INDEX"
,
columns
,
IndexType
.
createNonUnique
(
true
));
this
.
min
=
min
;
this
.
max
=
max
;
this
.
table
=
table
;
}
public
void
close
(
Session
session
)
throws
SQLException
{
...
...
@@ -41,6 +40,8 @@ public class RangeIndex extends BaseIndex {
}
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
throws
SQLException
{
long
min
=
table
.
getMin
(
session
);
long
max
=
table
.
getMax
(
session
);
long
start
=
Math
.
max
(
min
,
first
==
null
?
min
:
first
.
getValue
(
0
).
getLong
());
long
end
=
Math
.
min
(
max
,
last
==
null
?
max
:
last
.
getValue
(
0
).
getLong
());
return
new
RangeCursor
(
start
,
end
);
...
...
@@ -75,7 +76,7 @@ public class RangeIndex extends BaseIndex {
}
public
Cursor
findFirstOrLast
(
Session
session
,
boolean
first
)
throws
SQLException
{
long
pos
=
first
?
min
:
max
;
long
pos
=
first
?
table
.
getMin
(
session
)
:
table
.
getMax
(
session
)
;
return
new
RangeCursor
(
pos
,
pos
);
}
...
...
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
bfdaa836
...
...
@@ -9,6 +9,7 @@ package org.h2.table;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
import
org.h2.index.RangeIndex
;
...
...
@@ -25,9 +26,10 @@ import org.h2.value.Value;
public
class
RangeTable
extends
Table
{
public
static
final
String
NAME
=
"SYSTEM_RANGE"
;
private
final
long
min
,
max
;
public
RangeTable
(
Schema
schema
,
long
min
,
long
max
)
throws
SQLException
{
private
Expression
min
,
max
;
private
boolean
optimized
;
public
RangeTable
(
Schema
schema
,
Expression
min
,
Expression
max
)
throws
SQLException
{
super
(
schema
,
0
,
NAME
,
true
);
Column
[]
cols
=
new
Column
[]{
new
Column
(
"X"
,
Value
.
LONG
)
...
...
@@ -46,7 +48,7 @@ public class RangeTable extends Table {
}
public
String
getSQL
()
{
return
NAME
+
"("
+
min
+
", "
+
max
+
")"
;
return
NAME
+
"("
+
min
.
getSQL
()
+
", "
+
max
.
getSQL
()
+
")"
;
}
public
void
lock
(
Session
session
,
boolean
exclusive
,
boolean
force
)
throws
SQLException
{
...
...
@@ -91,7 +93,7 @@ public class RangeTable extends Table {
}
public
long
getRowCount
(
Session
session
)
throws
SQLException
{
return
max
-
min
;
return
getMax
(
session
)
-
getMin
(
session
)
;
}
public
String
getTableType
()
{
...
...
@@ -99,7 +101,25 @@ public class RangeTable extends Table {
}
public
Index
getScanIndex
(
Session
session
)
throws
SQLException
{
return
new
RangeIndex
(
this
,
IndexColumn
.
wrap
(
columns
),
min
,
max
);
return
new
RangeIndex
(
this
,
IndexColumn
.
wrap
(
columns
));
}
public
long
getMin
(
Session
s
)
throws
SQLException
{
optimize
(
s
);
return
min
.
getValue
(
s
).
getLong
();
}
public
long
getMax
(
Session
s
)
throws
SQLException
{
optimize
(
s
);
return
max
.
getValue
(
s
).
getLong
();
}
private
void
optimize
(
Session
s
)
throws
SQLException
{
if
(!
optimized
)
{
min
=
min
.
optimize
(
s
);
max
=
max
.
optimize
(
s
);
optimized
=
true
;
}
}
public
ObjectArray
getIndexes
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论