Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f3bde281
提交
f3bde281
authored
12月 02, 2015
作者:
S.Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
we have to hide current subQueryInfo if we are going to optimize query expression
上级
b860455f
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
56 行增加
和
9 行删除
+56
-9
Session.java
h2/src/main/org/h2/engine/Session.java
+20
-0
ConditionExists.java
h2/src/main/org/h2/expression/ConditionExists.java
+2
-1
ConditionInSelect.java
h2/src/main/org/h2/expression/ConditionInSelect.java
+2
-1
Subquery.java
h2/src/main/org/h2/expression/Subquery.java
+2
-2
TestTableEngines.java
h2/src/test/org/h2/test/db/TestTableEngines.java
+30
-5
没有找到文件。
h2/src/main/org/h2/engine/Session.java
浏览文件 @
f3bde281
...
@@ -17,6 +17,7 @@ import org.h2.command.Command;
...
@@ -17,6 +17,7 @@ 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.dml.Query
;
import
org.h2.command.dml.SetTypes
;
import
org.h2.command.dml.SetTypes
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.index.Index
;
import
org.h2.index.Index
;
...
@@ -115,6 +116,7 @@ public class Session extends SessionWithState {
...
@@ -115,6 +116,7 @@ public class Session extends SessionWithState {
private
long
modificationMetaID
=
-
1
;
private
long
modificationMetaID
=
-
1
;
private
SubQueryInfo
subQueryInfo
;
private
SubQueryInfo
subQueryInfo
;
private
int
parsingView
;
private
int
parsingView
;
private
int
preparingQueryExpression
;
private
volatile
SmallLRUCache
<
Object
,
ViewIndex
>
viewIndexCache
;
private
volatile
SmallLRUCache
<
Object
,
ViewIndex
>
viewIndexCache
;
private
HashMap
<
Object
,
ViewIndex
>
subQueryIndexCache
;
private
HashMap
<
Object
,
ViewIndex
>
subQueryIndexCache
;
private
boolean
joinBatchEnabled
;
private
boolean
joinBatchEnabled
;
...
@@ -187,6 +189,24 @@ public class Session extends SessionWithState {
...
@@ -187,6 +189,24 @@ public class Session extends SessionWithState {
return
parsingView
!=
0
;
return
parsingView
!=
0
;
}
}
public
void
optimizeQueryExpression
(
Query
query
)
{
// we have to hide current subQueryInfo if we are going to optimize query expression
SubQueryInfo
tmp
=
subQueryInfo
;
subQueryInfo
=
null
;
preparingQueryExpression
++;
try
{
query
.
prepare
();
}
finally
{
subQueryInfo
=
tmp
;
preparingQueryExpression
--;
}
}
public
boolean
isPreparingQueryExpression
()
{
assert
preparingQueryExpression
>=
0
;
return
preparingQueryExpression
!=
0
;
}
@Override
@Override
public
ArrayList
<
String
>
getClusterServers
()
{
public
ArrayList
<
String
>
getClusterServers
()
{
return
new
ArrayList
<
String
>();
return
new
ArrayList
<
String
>();
...
...
h2/src/main/org/h2/expression/ConditionExists.java
浏览文件 @
f3bde281
...
@@ -9,6 +9,7 @@ import org.h2.command.dml.Query;
...
@@ -9,6 +9,7 @@ import org.h2.command.dml.Query;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResult
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.SubQueryInfo
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
...
@@ -36,7 +37,7 @@ public class ConditionExists extends Condition {
...
@@ -36,7 +37,7 @@ public class ConditionExists extends Condition {
@Override
@Override
public
Expression
optimize
(
Session
session
)
{
public
Expression
optimize
(
Session
session
)
{
query
.
prepare
(
);
session
.
optimizeQueryExpression
(
query
);
return
this
;
return
this
;
}
}
...
...
h2/src/main/org/h2/expression/ConditionInSelect.java
浏览文件 @
f3bde281
...
@@ -13,6 +13,7 @@ import org.h2.index.IndexCondition;
...
@@ -13,6 +13,7 @@ import org.h2.index.IndexCondition;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.result.LocalResult
;
import
org.h2.result.LocalResult
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.SubQueryInfo
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
...
@@ -117,7 +118,7 @@ public class ConditionInSelect extends Condition {
...
@@ -117,7 +118,7 @@ public class ConditionInSelect extends Condition {
public
Expression
optimize
(
Session
session
)
{
public
Expression
optimize
(
Session
session
)
{
left
=
left
.
optimize
(
session
);
left
=
left
.
optimize
(
session
);
query
.
setRandomAccessResult
(
true
);
query
.
setRandomAccessResult
(
true
);
query
.
prepare
(
);
session
.
optimizeQueryExpression
(
query
);
if
(
query
.
getColumnCount
()
!=
1
)
{
if
(
query
.
getColumnCount
()
!=
1
)
{
throw
DbException
.
get
(
ErrorCode
.
SUBQUERY_IS_NOT_SINGLE_COLUMN
);
throw
DbException
.
get
(
ErrorCode
.
SUBQUERY_IS_NOT_SINGLE_COLUMN
);
}
}
...
...
h2/src/main/org/h2/expression/Subquery.java
浏览文件 @
f3bde281
...
@@ -6,13 +6,13 @@
...
@@ -6,13 +6,13 @@
package
org
.
h2
.
expression
;
package
org
.
h2
.
expression
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.dml.Query
;
import
org.h2.command.dml.Query
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultInterface
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.SubQueryInfo
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueArray
;
...
@@ -70,7 +70,7 @@ public class Subquery extends Expression {
...
@@ -70,7 +70,7 @@ public class Subquery extends Expression {
@Override
@Override
public
Expression
optimize
(
Session
session
)
{
public
Expression
optimize
(
Session
session
)
{
query
.
prepare
(
);
session
.
optimizeQueryExpression
(
query
);
return
this
;
return
this
;
}
}
...
...
h2/src/test/org/h2/test/db/TestTableEngines.java
浏览文件 @
f3bde281
...
@@ -73,6 +73,7 @@ public class TestTableEngines extends TestBase {
...
@@ -73,6 +73,7 @@ public class TestTableEngines extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testQueryExpressionFlag
();
testSubQueryInfo
();
testSubQueryInfo
();
testEarlyFilter
();
testEarlyFilter
();
testEngineParams
();
testEngineParams
();
...
@@ -347,6 +348,21 @@ public class TestTableEngines extends TestBase {
...
@@ -347,6 +348,21 @@ public class TestTableEngines extends TestBase {
deleteDb
(
"tableEngine"
);
deleteDb
(
"tableEngine"
);
}
}
private
void
testQueryExpressionFlag
()
throws
SQLException
{
deleteDb
(
"testQueryExpressionFlag"
);
Connection
conn
=
getConnection
(
"testQueryExpressionFlag"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table QRY_EXPR_TEST(id int) ENGINE \""
+
TreeSetIndexTableEngine
.
class
.
getName
()
+
"\""
);
stat
.
execute
(
"create table QRY_EXPR_TEST_NO(id int) ENGINE \""
+
TreeSetIndexTableEngine
.
class
.
getName
()
+
"\""
);
stat
.
executeQuery
(
"select 1 + (select 1 from QRY_EXPR_TEST)"
).
next
();
stat
.
executeQuery
(
"select 1 from QRY_EXPR_TEST_NO where id in (select id from QRY_EXPR_TEST)"
);
stat
.
executeQuery
(
"select 1 from QRY_EXPR_TEST_NO n "
+
"where exists(select 1 from QRY_EXPR_TEST y where y.id = n.id)"
);
deleteDb
(
"testQueryExpressionFlag"
);
}
private
void
testSubQueryInfo
()
throws
SQLException
{
private
void
testSubQueryInfo
()
throws
SQLException
{
deleteDb
(
"testSubQueryInfo"
);
deleteDb
(
"testSubQueryInfo"
);
Connection
conn
=
getConnection
(
"testSubQueryInfo"
);
Connection
conn
=
getConnection
(
"testSubQueryInfo"
);
...
@@ -1130,6 +1146,7 @@ public class TestTableEngines extends TestBase {
...
@@ -1130,6 +1146,7 @@ public class TestTableEngines extends TestBase {
@Override
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
doTests
(
session
);
return
getRowCount
(
session
)
+
Constants
.
COST_ROW_OFFSET
;
return
getRowCount
(
session
)
+
Constants
.
COST_ROW_OFFSET
;
}
}
};
};
...
@@ -1312,7 +1329,7 @@ public class TestTableEngines extends TestBase {
...
@@ -1312,7 +1329,7 @@ public class TestTableEngines extends TestBase {
@Override
@Override
public
IndexLookupBatch
createLookupBatch
(
final
TableFilter
filter
)
{
public
IndexLookupBatch
createLookupBatch
(
final
TableFilter
filter
)
{
assert
filter
.
getMasks
()
!=
null
||
"scan"
.
equals
(
getName
()
);
assert
0
(
filter
.
getMasks
()
!=
null
||
"scan"
.
equals
(
getName
()),
"masks"
);
final
int
preferedSize
=
preferedBatchSize
;
final
int
preferedSize
=
preferedBatchSize
;
if
(
preferedSize
==
0
)
{
if
(
preferedSize
==
0
)
{
return
null
;
return
null
;
...
@@ -1454,9 +1471,7 @@ public class TestTableEngines extends TestBase {
...
@@ -1454,9 +1471,7 @@ public class TestTableEngines extends TestBase {
}
}
}
}
@Override
protected
void
doTests
(
Session
session
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
getTable
().
getName
().
equals
(
"SUB_QUERY_TEST"
))
{
if
(
getTable
().
getName
().
equals
(
"SUB_QUERY_TEST"
))
{
checkInfo
(
session
.
getSubQueryInfo
());
checkInfo
(
session
.
getSubQueryInfo
());
}
else
if
(
getTable
().
getName
().
equals
(
"EXPR_TEST"
))
{
}
else
if
(
getTable
().
getName
().
equals
(
"EXPR_TEST"
))
{
...
@@ -1465,7 +1480,17 @@ public class TestTableEngines extends TestBase {
...
@@ -1465,7 +1480,17 @@ public class TestTableEngines extends TestBase {
String
alias
=
alias
(
session
.
getSubQueryInfo
());
String
alias
=
alias
(
session
.
getSubQueryInfo
());
assert0
(
alias
.
equals
(
"ZZ"
),
"select expression sub-query: "
+
alias
);
assert0
(
alias
.
equals
(
"ZZ"
),
"select expression sub-query: "
+
alias
);
assert0
(
session
.
getSubQueryInfo
().
getUpper
()
==
null
,
"upper"
);
assert0
(
session
.
getSubQueryInfo
().
getUpper
()
==
null
,
"upper"
);
}
else
if
(
getTable
().
getName
().
equals
(
"QRY_EXPR_TEST"
))
{
assert0
(
session
.
isPreparingQueryExpression
(),
"preparing query expression"
);
}
else
if
(
getTable
().
getName
().
equals
(
"QRY_EXPR_TEST_NO"
))
{
assert0
(!
session
.
isPreparingQueryExpression
(),
"not preparing query expression"
);
}
}
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
doTests
(
session
);
return
getCostRangeIndex
(
masks
,
set
.
size
(),
filters
,
filter
,
sortOrder
);
return
getCostRangeIndex
(
masks
,
set
.
size
(),
filters
,
filter
,
sortOrder
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论