Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
87562a00
提交
87562a00
authored
4月 03, 2017
作者:
Sergi Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Choose minimal covering index for MIN/MAX and DISTINCT
上级
cb88fe35
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
12 行删除
+25
-12
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-1
Aggregate.java
h2/src/main/org/h2/expression/Aggregate.java
+4
-4
Table.java
h2/src/main/org/h2/table/Table.java
+20
-7
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
87562a00
...
@@ -889,7 +889,7 @@ public class Select extends Query {
...
@@ -889,7 +889,7 @@ public class Select extends Query {
Column
column
=
((
ExpressionColumn
)
expr
).
getColumn
();
Column
column
=
((
ExpressionColumn
)
expr
).
getColumn
();
int
selectivity
=
column
.
getSelectivity
();
int
selectivity
=
column
.
getSelectivity
();
Index
columnIndex
=
topTableFilter
.
getTable
().
Index
columnIndex
=
topTableFilter
.
getTable
().
getIndexForColumn
(
column
);
getIndexForColumn
(
column
,
false
,
true
);
if
(
columnIndex
!=
null
&&
if
(
columnIndex
!=
null
&&
selectivity
!=
Constants
.
SELECTIVITY_DEFAULT
&&
selectivity
!=
Constants
.
SELECTIVITY_DEFAULT
&&
selectivity
<
20
)
{
selectivity
<
20
)
{
...
...
h2/src/main/org/h2/expression/Aggregate.java
浏览文件 @
87562a00
...
@@ -287,7 +287,7 @@ public class Aggregate extends Expression {
...
@@ -287,7 +287,7 @@ public class Aggregate extends Expression {
case
MIN:
case
MIN:
case
MAX:
case
MAX:
boolean
first
=
type
==
MIN
;
boolean
first
=
type
==
MIN
;
Index
index
=
getColumnIndex
();
Index
index
=
get
MinMax
ColumnIndex
();
int
sortType
=
index
.
getIndexColumns
()[
0
].
sortType
;
int
sortType
=
index
.
getIndexColumns
()[
0
].
sortType
;
if
((
sortType
&
SortOrder
.
DESCENDING
)
!=
0
)
{
if
((
sortType
&
SortOrder
.
DESCENDING
)
!=
0
)
{
first
=
!
first
;
first
=
!
first
;
...
@@ -575,14 +575,14 @@ public class Aggregate extends Expression {
...
@@ -575,14 +575,14 @@ public class Aggregate extends Expression {
return
text
+
StringUtils
.
enclose
(
on
.
getSQL
());
return
text
+
StringUtils
.
enclose
(
on
.
getSQL
());
}
}
private
Index
getColumnIndex
()
{
private
Index
get
MinMax
ColumnIndex
()
{
if
(
on
instanceof
ExpressionColumn
)
{
if
(
on
instanceof
ExpressionColumn
)
{
ExpressionColumn
col
=
(
ExpressionColumn
)
on
;
ExpressionColumn
col
=
(
ExpressionColumn
)
on
;
Column
column
=
col
.
getColumn
();
Column
column
=
col
.
getColumn
();
TableFilter
filter
=
col
.
getTableFilter
();
TableFilter
filter
=
col
.
getTableFilter
();
if
(
filter
!=
null
)
{
if
(
filter
!=
null
)
{
Table
table
=
filter
.
getTable
();
Table
table
=
filter
.
getTable
();
Index
index
=
table
.
getIndexForColumn
(
column
);
Index
index
=
table
.
getIndexForColumn
(
column
,
true
,
false
);
return
index
;
return
index
;
}
}
}
}
...
@@ -602,7 +602,7 @@ public class Aggregate extends Expression {
...
@@ -602,7 +602,7 @@ public class Aggregate extends Expression {
return
visitor
.
getTable
().
canGetRowCount
();
return
visitor
.
getTable
().
canGetRowCount
();
case
MIN:
case
MIN:
case
MAX:
case
MAX:
Index
index
=
getColumnIndex
();
Index
index
=
get
MinMax
ColumnIndex
();
return
index
!=
null
;
return
index
!=
null
;
default
:
default
:
return
false
;
return
false
;
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
87562a00
...
@@ -1050,22 +1050,35 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -1050,22 +1050,35 @@ public abstract class Table extends SchemaObjectBase {
* This method returns null if no matching index is found.
* This method returns null if no matching index is found.
*
*
* @param column the column
* @param column the column
* @param needGetFirstOrLast if the returned index must be able
* to do {@link Index#canGetFirstOrLast()}
* @param needFindNext if the returned index must be able to do
* {@link Index#findNext(Session, SearchRow, SearchRow)}
* @return the index or null
* @return the index or null
*/
*/
public
Index
getIndexForColumn
(
Column
column
)
{
public
Index
getIndexForColumn
(
Column
column
,
boolean
needGetFirstOrLast
,
boolean
needFindNext
)
{
ArrayList
<
Index
>
indexes
=
getIndexes
();
ArrayList
<
Index
>
indexes
=
getIndexes
();
Index
result
=
null
;
if
(
indexes
!=
null
)
{
if
(
indexes
!=
null
)
{
for
(
int
i
=
1
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
for
(
int
i
=
1
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
Index
index
=
indexes
.
get
(
i
);
Index
index
=
indexes
.
get
(
i
);
if
(
index
.
canGetFirstOrLast
())
{
if
(
needGetFirstOrLast
&&
!
index
.
canGetFirstOrLast
())
{
int
idx
=
index
.
getColumnIndex
(
column
);
continue
;
if
(
idx
==
0
)
{
return
index
;
}
}
if
(
needFindNext
&&
!
index
.
canFindNext
())
{
continue
;
}
}
int
idx
=
index
.
getColumnIndex
(
column
);
// choose the minimal covering index with the needed first column
// to work consistently with execution plan from Optimizer
if
(
idx
==
0
&&
(
result
==
null
||
result
.
getColumns
().
length
>
index
.
getColumns
().
length
))
{
result
=
index
;
}
}
}
}
return
null
;
}
return
result
;
}
}
public
boolean
getOnCommitDrop
()
{
public
boolean
getOnCommitDrop
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论