Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b0b00641
提交
b0b00641
authored
3月 13, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
User defined functions can now be deterministic.
上级
2ae49669
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
75 行增加
和
38 行删除
+75
-38
Parser.java
h2/src/main/org/h2/command/Parser.java
+2
-1
CreateFunctionAlias.java
h2/src/main/org/h2/command/ddl/CreateFunctionAlias.java
+6
-0
FunctionAlias.java
h2/src/main/org/h2/engine/FunctionAlias.java
+12
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+35
-33
FunctionCall.java
h2/src/main/org/h2/expression/FunctionCall.java
+6
-0
FunctionInfo.java
h2/src/main/org/h2/expression/FunctionInfo.java
+1
-1
JavaFunction.java
h2/src/main/org/h2/expression/JavaFunction.java
+13
-3
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
b0b00641
...
@@ -965,7 +965,7 @@ public class Parser {
...
@@ -965,7 +965,7 @@ public class Parser {
if
(!(
func
instanceof
FunctionCall
))
{
if
(!(
func
instanceof
FunctionCall
))
{
throw
getSyntaxError
();
throw
getSyntaxError
();
}
}
table
=
new
FunctionTable
(
mainSchema
,
session
,
(
FunctionCall
)
func
);
table
=
new
FunctionTable
(
mainSchema
,
session
,
func
,
(
FunctionCall
)
func
);
}
}
}
else
if
(
"DUAL"
.
equals
(
tableName
))
{
}
else
if
(
"DUAL"
.
equals
(
tableName
))
{
table
=
getDualTable
();
table
=
getDualTable
();
...
@@ -3765,6 +3765,7 @@ public class Parser {
...
@@ -3765,6 +3765,7 @@ public class Parser {
}
}
command
.
setAliasName
(
name
);
command
.
setAliasName
(
name
);
command
.
setIfNotExists
(
ifNotExists
);
command
.
setIfNotExists
(
ifNotExists
);
command
.
setDeterministic
(
readIf
(
"DETERMINISTIC"
));
read
(
"FOR"
);
read
(
"FOR"
);
command
.
setJavaClassMethod
(
readUniqueIdentifier
());
command
.
setJavaClassMethod
(
readUniqueIdentifier
());
return
command
;
return
command
;
...
...
h2/src/main/org/h2/command/ddl/CreateFunctionAlias.java
浏览文件 @
b0b00641
...
@@ -22,6 +22,7 @@ public class CreateFunctionAlias extends DefineCommand {
...
@@ -22,6 +22,7 @@ public class CreateFunctionAlias extends DefineCommand {
private
String
aliasName
;
private
String
aliasName
;
private
String
javaClassMethod
;
private
String
javaClassMethod
;
private
boolean
deterministic
;
private
boolean
ifNotExists
;
private
boolean
ifNotExists
;
private
boolean
force
;
private
boolean
force
;
...
@@ -40,6 +41,7 @@ public class CreateFunctionAlias extends DefineCommand {
...
@@ -40,6 +41,7 @@ public class CreateFunctionAlias extends DefineCommand {
}
else
{
}
else
{
int
id
=
getObjectId
(
false
,
true
);
int
id
=
getObjectId
(
false
,
true
);
FunctionAlias
functionAlias
=
new
FunctionAlias
(
db
,
id
,
aliasName
,
javaClassMethod
,
force
);
FunctionAlias
functionAlias
=
new
FunctionAlias
(
db
,
id
,
aliasName
,
javaClassMethod
,
force
);
functionAlias
.
setDeterministic
(
deterministic
);
db
.
addDatabaseObject
(
session
,
functionAlias
);
db
.
addDatabaseObject
(
session
,
functionAlias
);
}
}
return
0
;
return
0
;
...
@@ -61,4 +63,8 @@ public class CreateFunctionAlias extends DefineCommand {
...
@@ -61,4 +63,8 @@ public class CreateFunctionAlias extends DefineCommand {
this
.
force
=
force
;
this
.
force
=
force
;
}
}
public
void
setDeterministic
(
boolean
deterministic
)
{
this
.
deterministic
=
deterministic
;
}
}
}
h2/src/main/org/h2/engine/FunctionAlias.java
浏览文件 @
b0b00641
...
@@ -36,6 +36,7 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -36,6 +36,7 @@ public class FunctionAlias extends DbObjectBase {
private
String
className
;
private
String
className
;
private
String
methodName
;
private
String
methodName
;
private
JavaMethod
[]
javaMethods
;
private
JavaMethod
[]
javaMethods
;
private
boolean
deterministic
;
public
FunctionAlias
(
Database
db
,
int
id
,
String
name
,
String
javaClassMethod
,
boolean
force
)
throws
SQLException
{
public
FunctionAlias
(
Database
db
,
int
id
,
String
name
,
String
javaClassMethod
,
boolean
force
)
throws
SQLException
{
initDbObjectBase
(
db
,
id
,
name
,
Trace
.
FUNCTION
);
initDbObjectBase
(
db
,
id
,
name
,
Trace
.
FUNCTION
);
...
@@ -130,6 +131,9 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -130,6 +131,9 @@ public class FunctionAlias extends DbObjectBase {
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"CREATE FORCE ALIAS "
);
buff
.
append
(
"CREATE FORCE ALIAS "
);
buff
.
append
(
getSQL
());
buff
.
append
(
getSQL
());
if
(
deterministic
)
{
buff
.
append
(
" DETERMINISTIC"
);
}
buff
.
append
(
" FOR "
);
buff
.
append
(
" FOR "
);
buff
.
append
(
Parser
.
quoteIdentifier
(
className
+
"."
+
methodName
));
buff
.
append
(
Parser
.
quoteIdentifier
(
className
+
"."
+
methodName
));
return
buff
.
toString
();
return
buff
.
toString
();
...
@@ -350,4 +354,12 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -350,4 +354,12 @@ public class FunctionAlias extends DbObjectBase {
}
}
public
void
setDeterministic
(
boolean
deterministic
)
{
this
.
deterministic
=
deterministic
;
}
public
boolean
isDeterministic
()
{
return
deterministic
;
}
}
}
h2/src/main/org/h2/expression/Function.java
浏览文件 @
b0b00641
...
@@ -72,8 +72,6 @@ import org.h2.value.ValueUuid;
...
@@ -72,8 +72,6 @@ import org.h2.value.ValueUuid;
* This class implements most built-in functions of this database.
* This class implements most built-in functions of this database.
*/
*/
public
class
Function
extends
Expression
implements
FunctionCall
{
public
class
Function
extends
Expression
implements
FunctionCall
{
// TODO functions: add function hashcode(value)
public
static
final
int
ABS
=
0
,
ACOS
=
1
,
ASIN
=
2
,
ATAN
=
3
,
ATAN2
=
4
,
BITAND
=
5
,
BITOR
=
6
,
BITXOR
=
7
,
public
static
final
int
ABS
=
0
,
ACOS
=
1
,
ASIN
=
2
,
ATAN
=
3
,
ATAN2
=
4
,
BITAND
=
5
,
BITOR
=
6
,
BITXOR
=
7
,
CEILING
=
8
,
COS
=
9
,
COT
=
10
,
DEGREES
=
11
,
EXP
=
12
,
FLOOR
=
13
,
LOG
=
14
,
LOG10
=
15
,
MOD
=
16
,
CEILING
=
8
,
COS
=
9
,
COT
=
10
,
DEGREES
=
11
,
EXP
=
12
,
FLOOR
=
13
,
LOG
=
14
,
LOG10
=
15
,
MOD
=
16
,
PI
=
17
,
POWER
=
18
,
RADIANS
=
19
,
RAND
=
20
,
ROUND
=
21
,
ROUNDMAGIC
=
22
,
SIGN
=
23
,
SIN
=
24
,
SQRT
=
25
,
PI
=
17
,
POWER
=
18
,
RADIANS
=
19
,
RAND
=
20
,
ROUND
=
21
,
ROUNDMAGIC
=
22
,
SIGN
=
23
,
SIN
=
24
,
SQRT
=
25
,
...
@@ -183,7 +181,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -183,7 +181,7 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"RADIANS"
,
RADIANS
,
1
,
Value
.
DOUBLE
);
addFunction
(
"RADIANS"
,
RADIANS
,
1
,
Value
.
DOUBLE
);
// RAND without argument: get the next value
// RAND without argument: get the next value
// RAND with one argument: seed the random generator
// RAND with one argument: seed the random generator
addFunctionNot
Const
(
"RAND"
,
RAND
,
VAR_ARGS
,
Value
.
DOUBLE
);
addFunctionNot
Deterministic
(
"RAND"
,
RAND
,
VAR_ARGS
,
Value
.
DOUBLE
);
addFunction
(
"ROUND"
,
ROUND
,
2
,
Value
.
DOUBLE
);
addFunction
(
"ROUND"
,
ROUND
,
2
,
Value
.
DOUBLE
);
addFunction
(
"ROUNDMAGIC"
,
ROUNDMAGIC
,
1
,
Value
.
DOUBLE
);
addFunction
(
"ROUNDMAGIC"
,
ROUNDMAGIC
,
1
,
Value
.
DOUBLE
);
addFunction
(
"SIGN"
,
SIGN
,
1
,
Value
.
INT
);
addFunction
(
"SIGN"
,
SIGN
,
1
,
Value
.
INT
);
...
@@ -194,12 +192,12 @@ public class Function extends Expression implements FunctionCall {
...
@@ -194,12 +192,12 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"HASH"
,
HASH
,
3
,
Value
.
BYTES
);
addFunction
(
"HASH"
,
HASH
,
3
,
Value
.
BYTES
);
addFunction
(
"ENCRYPT"
,
ENCRYPT
,
3
,
Value
.
BYTES
);
addFunction
(
"ENCRYPT"
,
ENCRYPT
,
3
,
Value
.
BYTES
);
addFunction
(
"DECRYPT"
,
DECRYPT
,
3
,
Value
.
BYTES
);
addFunction
(
"DECRYPT"
,
DECRYPT
,
3
,
Value
.
BYTES
);
addFunctionNot
Const
(
"SECURE_RAND"
,
SECURE_RAND
,
1
,
Value
.
BYTES
);
addFunctionNot
Deterministic
(
"SECURE_RAND"
,
SECURE_RAND
,
1
,
Value
.
BYTES
);
addFunction
(
"COMPRESS"
,
COMPRESS
,
VAR_ARGS
,
Value
.
BYTES
);
addFunction
(
"COMPRESS"
,
COMPRESS
,
VAR_ARGS
,
Value
.
BYTES
);
addFunction
(
"EXPAND"
,
EXPAND
,
1
,
Value
.
BYTES
);
addFunction
(
"EXPAND"
,
EXPAND
,
1
,
Value
.
BYTES
);
addFunction
(
"ZERO"
,
ZERO
,
0
,
Value
.
INT
);
addFunction
(
"ZERO"
,
ZERO
,
0
,
Value
.
INT
);
addFunctionNot
Const
(
"RANDOM_UUID"
,
RANDOM_UUID
,
0
,
Value
.
UUID
);
addFunctionNot
Deterministic
(
"RANDOM_UUID"
,
RANDOM_UUID
,
0
,
Value
.
UUID
);
addFunctionNot
Const
(
"SYS_GUID"
,
RANDOM_UUID
,
0
,
Value
.
UUID
);
addFunctionNot
Deterministic
(
"SYS_GUID"
,
RANDOM_UUID
,
0
,
Value
.
UUID
);
// string
// string
addFunction
(
"ASCII"
,
ASCII
,
1
,
Value
.
INT
);
addFunction
(
"ASCII"
,
ASCII
,
1
,
Value
.
INT
);
addFunction
(
"BIT_LENGTH"
,
BIT_LENGTH
,
1
,
Value
.
INT
);
addFunction
(
"BIT_LENGTH"
,
BIT_LENGTH
,
1
,
Value
.
INT
);
...
@@ -251,12 +249,12 @@ public class Function extends Expression implements FunctionCall {
...
@@ -251,12 +249,12 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"LPAD"
,
LPAD
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"LPAD"
,
LPAD
,
VAR_ARGS
,
Value
.
STRING
);
// date
// date
addFunctionNot
Const
(
"CURRENT_DATE"
,
CURRENT_DATE
,
0
,
Value
.
DATE
);
addFunctionNot
Deterministic
(
"CURRENT_DATE"
,
CURRENT_DATE
,
0
,
Value
.
DATE
);
addFunctionNot
Const
(
"CURDATE"
,
CURDATE
,
0
,
Value
.
DATE
);
addFunctionNot
Deterministic
(
"CURDATE"
,
CURDATE
,
0
,
Value
.
DATE
);
addFunctionNot
Const
(
"CURRENT_TIME"
,
CURRENT_TIME
,
0
,
Value
.
TIME
);
addFunctionNot
Deterministic
(
"CURRENT_TIME"
,
CURRENT_TIME
,
0
,
Value
.
TIME
);
addFunctionNot
Const
(
"CURTIME"
,
CURTIME
,
0
,
Value
.
TIME
);
addFunctionNot
Deterministic
(
"CURTIME"
,
CURTIME
,
0
,
Value
.
TIME
);
addFunctionNot
Const
(
"CURRENT_TIMESTAMP"
,
CURRENT_TIMESTAMP
,
VAR_ARGS
,
Value
.
TIMESTAMP
);
addFunctionNot
Deterministic
(
"CURRENT_TIMESTAMP"
,
CURRENT_TIMESTAMP
,
VAR_ARGS
,
Value
.
TIMESTAMP
);
addFunctionNot
Const
(
"NOW"
,
NOW
,
VAR_ARGS
,
Value
.
TIMESTAMP
);
addFunctionNot
Deterministic
(
"NOW"
,
NOW
,
VAR_ARGS
,
Value
.
TIMESTAMP
);
addFunction
(
"DATEADD"
,
DATE_ADD
,
3
,
Value
.
TIMESTAMP
);
addFunction
(
"DATEADD"
,
DATE_ADD
,
3
,
Value
.
TIMESTAMP
);
addFunction
(
"DATEDIFF"
,
DATE_DIFF
,
3
,
Value
.
LONG
);
addFunction
(
"DATEDIFF"
,
DATE_DIFF
,
3
,
Value
.
LONG
);
addFunction
(
"DAYNAME"
,
DAY_NAME
,
1
,
Value
.
STRING
);
addFunction
(
"DAYNAME"
,
DAY_NAME
,
1
,
Value
.
STRING
);
...
@@ -283,14 +281,14 @@ public class Function extends Expression implements FunctionCall {
...
@@ -283,14 +281,14 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"ISO_WEEK"
,
ISO_WEEK
,
1
,
Value
.
INT
);
addFunction
(
"ISO_WEEK"
,
ISO_WEEK
,
1
,
Value
.
INT
);
addFunction
(
"ISO_DAY_OF_WEEK"
,
ISO_DAY_OF_WEEK
,
1
,
Value
.
INT
);
addFunction
(
"ISO_DAY_OF_WEEK"
,
ISO_DAY_OF_WEEK
,
1
,
Value
.
INT
);
// system
// system
addFunctionNot
Const
(
"DATABASE"
,
DATABASE
,
0
,
Value
.
STRING
);
addFunctionNot
Deterministic
(
"DATABASE"
,
DATABASE
,
0
,
Value
.
STRING
);
addFunctionNot
Const
(
"USER"
,
USER
,
0
,
Value
.
STRING
);
addFunctionNot
Deterministic
(
"USER"
,
USER
,
0
,
Value
.
STRING
);
addFunctionNot
Const
(
"CURRENT_USER"
,
CURRENT_USER
,
0
,
Value
.
STRING
);
addFunctionNot
Deterministic
(
"CURRENT_USER"
,
CURRENT_USER
,
0
,
Value
.
STRING
);
addFunctionNot
Const
(
"IDENTITY"
,
IDENTITY
,
0
,
Value
.
LONG
);
addFunctionNot
Deterministic
(
"IDENTITY"
,
IDENTITY
,
0
,
Value
.
LONG
);
addFunctionNot
Const
(
"IDENTITY_VAL_LOCAL"
,
IDENTITY
,
0
,
Value
.
LONG
);
addFunctionNot
Deterministic
(
"IDENTITY_VAL_LOCAL"
,
IDENTITY
,
0
,
Value
.
LONG
);
addFunctionNot
Const
(
"LAST_INSERT_ID"
,
IDENTITY
,
0
,
Value
.
LONG
);
addFunctionNot
Deterministic
(
"LAST_INSERT_ID"
,
IDENTITY
,
0
,
Value
.
LONG
);
addFunctionNot
Const
(
"AUTOCOMMIT"
,
AUTOCOMMIT
,
0
,
Value
.
BOOLEAN
);
addFunctionNot
Deterministic
(
"AUTOCOMMIT"
,
AUTOCOMMIT
,
0
,
Value
.
BOOLEAN
);
addFunctionNot
Const
(
"READONLY"
,
READONLY
,
0
,
Value
.
BOOLEAN
);
addFunctionNot
Deterministic
(
"READONLY"
,
READONLY
,
0
,
Value
.
BOOLEAN
);
addFunction
(
"DATABASE_PATH"
,
DATABASE_PATH
,
0
,
Value
.
STRING
);
addFunction
(
"DATABASE_PATH"
,
DATABASE_PATH
,
0
,
Value
.
STRING
);
addFunction
(
"LOCK_TIMEOUT"
,
LOCK_TIMEOUT
,
0
,
Value
.
INT
);
addFunction
(
"LOCK_TIMEOUT"
,
LOCK_TIMEOUT
,
0
,
Value
.
INT
);
addFunctionWithNull
(
"IFNULL"
,
IFNULL
,
2
,
Value
.
NULL
);
addFunctionWithNull
(
"IFNULL"
,
IFNULL
,
2
,
Value
.
NULL
);
...
@@ -301,16 +299,16 @@ public class Function extends Expression implements FunctionCall {
...
@@ -301,16 +299,16 @@ public class Function extends Expression implements FunctionCall {
addFunctionWithNull
(
"NVL"
,
COALESCE
,
VAR_ARGS
,
Value
.
NULL
);
addFunctionWithNull
(
"NVL"
,
COALESCE
,
VAR_ARGS
,
Value
.
NULL
);
addFunctionWithNull
(
"NULLIF"
,
NULLIF
,
2
,
Value
.
NULL
);
addFunctionWithNull
(
"NULLIF"
,
NULLIF
,
2
,
Value
.
NULL
);
addFunctionWithNull
(
"CASE"
,
CASE
,
VAR_ARGS
,
Value
.
NULL
);
addFunctionWithNull
(
"CASE"
,
CASE
,
VAR_ARGS
,
Value
.
NULL
);
addFunctionNot
Const
(
"NEXTVAL"
,
NEXTVAL
,
VAR_ARGS
,
Value
.
LONG
);
addFunctionNot
Deterministic
(
"NEXTVAL"
,
NEXTVAL
,
VAR_ARGS
,
Value
.
LONG
);
addFunctionNot
Const
(
"CURRVAL"
,
CURRVAL
,
VAR_ARGS
,
Value
.
LONG
);
addFunctionNot
Deterministic
(
"CURRVAL"
,
CURRVAL
,
VAR_ARGS
,
Value
.
LONG
);
addFunction
(
"ARRAY_GET"
,
ARRAY_GET
,
2
,
Value
.
STRING
);
addFunction
(
"ARRAY_GET"
,
ARRAY_GET
,
2
,
Value
.
STRING
);
addFunction
(
"CSVREAD"
,
CSVREAD
,
VAR_ARGS
,
Value
.
RESULT_SET
,
false
,
false
);
addFunction
(
"CSVREAD"
,
CSVREAD
,
VAR_ARGS
,
Value
.
RESULT_SET
,
false
,
false
);
addFunction
(
"CSVWRITE"
,
CSVWRITE
,
VAR_ARGS
,
Value
.
INT
,
false
,
false
);
addFunction
(
"CSVWRITE"
,
CSVWRITE
,
VAR_ARGS
,
Value
.
INT
,
false
,
false
);
addFunctionNot
Const
(
"MEMORY_FREE"
,
MEMORY_FREE
,
0
,
Value
.
INT
);
addFunctionNot
Deterministic
(
"MEMORY_FREE"
,
MEMORY_FREE
,
0
,
Value
.
INT
);
addFunctionNot
Const
(
"MEMORY_USED"
,
MEMORY_USED
,
0
,
Value
.
INT
);
addFunctionNot
Deterministic
(
"MEMORY_USED"
,
MEMORY_USED
,
0
,
Value
.
INT
);
addFunctionNot
Const
(
"LOCK_MODE"
,
LOCK_MODE
,
0
,
Value
.
INT
);
addFunctionNot
Deterministic
(
"LOCK_MODE"
,
LOCK_MODE
,
0
,
Value
.
INT
);
addFunctionNot
Const
(
"SCHEMA"
,
SCHEMA
,
0
,
Value
.
STRING
);
addFunctionNot
Deterministic
(
"SCHEMA"
,
SCHEMA
,
0
,
Value
.
STRING
);
addFunctionNot
Const
(
"SESSION_ID"
,
SESSION_ID
,
0
,
Value
.
INT
);
addFunctionNot
Deterministic
(
"SESSION_ID"
,
SESSION_ID
,
0
,
Value
.
INT
);
addFunction
(
"ARRAY_LENGTH"
,
ARRAY_LENGTH
,
1
,
Value
.
INT
);
addFunction
(
"ARRAY_LENGTH"
,
ARRAY_LENGTH
,
1
,
Value
.
INT
);
addFunction
(
"LINK_SCHEMA"
,
LINK_SCHEMA
,
6
,
Value
.
RESULT_SET
);
addFunction
(
"LINK_SCHEMA"
,
LINK_SCHEMA
,
6
,
Value
.
RESULT_SET
);
addFunctionWithNull
(
"LEAST"
,
LEAST
,
VAR_ARGS
,
Value
.
NULL
);
addFunctionWithNull
(
"LEAST"
,
LEAST
,
VAR_ARGS
,
Value
.
NULL
);
...
@@ -318,7 +316,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -318,7 +316,7 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"CANCEL_SESSION"
,
CANCEL_SESSION
,
1
,
Value
.
BOOLEAN
);
addFunction
(
"CANCEL_SESSION"
,
CANCEL_SESSION
,
1
,
Value
.
BOOLEAN
);
addFunction
(
"SET"
,
SET
,
2
,
Value
.
NULL
,
false
,
false
);
addFunction
(
"SET"
,
SET
,
2
,
Value
.
NULL
,
false
,
false
);
addFunction
(
"FILE_READ"
,
FILE_READ
,
VAR_ARGS
,
Value
.
NULL
,
false
,
true
);
addFunction
(
"FILE_READ"
,
FILE_READ
,
VAR_ARGS
,
Value
.
NULL
,
false
,
true
);
addFunctionNot
Const
(
"TRANSACTION_ID"
,
TRANSACTION_ID
,
0
,
Value
.
STRING
);
addFunctionNot
Deterministic
(
"TRANSACTION_ID"
,
TRANSACTION_ID
,
0
,
Value
.
STRING
);
// TableFunction
// TableFunction
addFunctionWithNull
(
"TABLE"
,
TABLE
,
VAR_ARGS
,
Value
.
RESULT_SET
);
addFunctionWithNull
(
"TABLE"
,
TABLE
,
VAR_ARGS
,
Value
.
RESULT_SET
);
...
@@ -336,18 +334,18 @@ public class Function extends Expression implements FunctionCall {
...
@@ -336,18 +334,18 @@ public class Function extends Expression implements FunctionCall {
}
}
private
static
void
addFunction
(
String
name
,
int
type
,
int
parameterCount
,
int
dataType
,
private
static
void
addFunction
(
String
name
,
int
type
,
int
parameterCount
,
int
dataType
,
boolean
nullIfParameterIsNull
,
boolean
isDeterm
)
{
boolean
nullIfParameterIsNull
,
boolean
deterministic
)
{
FunctionInfo
info
=
new
FunctionInfo
();
FunctionInfo
info
=
new
FunctionInfo
();
info
.
name
=
name
;
info
.
name
=
name
;
info
.
type
=
type
;
info
.
type
=
type
;
info
.
parameterCount
=
parameterCount
;
info
.
parameterCount
=
parameterCount
;
info
.
dataType
=
dataType
;
info
.
dataType
=
dataType
;
info
.
nullIfParameterIsNull
=
nullIfParameterIsNull
;
info
.
nullIfParameterIsNull
=
nullIfParameterIsNull
;
info
.
isDeterministic
=
isDeterm
;
info
.
deterministic
=
deterministic
;
FUNCTIONS
.
put
(
name
,
info
);
FUNCTIONS
.
put
(
name
,
info
);
}
}
private
static
void
addFunctionNot
Const
(
String
name
,
int
type
,
int
parameterCount
,
int
dataType
)
{
private
static
void
addFunctionNot
Deterministic
(
String
name
,
int
type
,
int
parameterCount
,
int
dataType
)
{
addFunction
(
name
,
type
,
parameterCount
,
dataType
,
true
,
false
);
addFunction
(
name
,
type
,
parameterCount
,
dataType
,
true
,
false
);
}
}
...
@@ -1606,7 +1604,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1606,7 +1604,7 @@ public class Function extends Expression implements FunctionCall {
}
}
public
Expression
optimize
(
Session
session
)
throws
SQLException
{
public
Expression
optimize
(
Session
session
)
throws
SQLException
{
boolean
allConst
=
info
.
isD
eterministic
;
boolean
allConst
=
info
.
d
eterministic
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Expression
e
=
args
[
i
].
optimize
(
session
);
Expression
e
=
args
[
i
].
optimize
(
session
);
args
[
i
]
=
e
;
args
[
i
]
=
e
;
...
@@ -1919,7 +1917,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1919,7 +1917,7 @@ public class Function extends Expression implements FunctionCall {
}
}
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
if
(
visitor
.
getType
()
==
ExpressionVisitor
.
DETERMINISTIC
&&
!
info
.
isD
eterministic
)
{
if
(
visitor
.
getType
()
==
ExpressionVisitor
.
DETERMINISTIC
&&
!
info
.
d
eterministic
)
{
return
false
;
return
false
;
}
}
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
...
@@ -1939,4 +1937,8 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1939,4 +1937,8 @@ public class Function extends Expression implements FunctionCall {
return
cost
;
return
cost
;
}
}
public
boolean
isDeterministic
()
{
return
info
.
deterministic
;
}
}
}
h2/src/main/org/h2/expression/FunctionCall.java
浏览文件 @
b0b00641
...
@@ -78,4 +78,10 @@ public interface FunctionCall {
...
@@ -78,4 +78,10 @@ public interface FunctionCall {
*/
*/
String
getSQL
();
String
getSQL
();
/**
* Whether the function always returns the same result for the same parameters.
*
* @return true if it does
*/
boolean
isDeterministic
();
}
}
h2/src/main/org/h2/expression/FunctionInfo.java
浏览文件 @
b0b00641
...
@@ -39,5 +39,5 @@ class FunctionInfo {
...
@@ -39,5 +39,5 @@ class FunctionInfo {
/**
/**
* If this function always returns the same value for the same parameters.
* If this function always returns the same value for the same parameters.
*/
*/
boolean
isD
eterministic
;
boolean
d
eterministic
;
}
}
h2/src/main/org/h2/expression/JavaFunction.java
浏览文件 @
b0b00641
...
@@ -52,6 +52,9 @@ public class JavaFunction extends Expression implements FunctionCall {
...
@@ -52,6 +52,9 @@ public class JavaFunction extends Expression implements FunctionCall {
Expression
e
=
args
[
i
].
optimize
(
session
);
Expression
e
=
args
[
i
].
optimize
(
session
);
args
[
i
]
=
e
;
args
[
i
]
=
e
;
}
}
if
(
isEverything
(
ExpressionVisitor
.
DETERMINISTIC
))
{
return
ValueExpression
.
get
(
getValue
(
session
));
}
return
this
;
return
this
;
}
}
...
@@ -120,9 +123,12 @@ public class JavaFunction extends Expression implements FunctionCall {
...
@@ -120,9 +123,12 @@ public class JavaFunction extends Expression implements FunctionCall {
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
switch
(
visitor
.
getType
())
{
switch
(
visitor
.
getType
())
{
case
ExpressionVisitor
.
DETERMINISTIC
:
case
ExpressionVisitor
.
DETERMINISTIC
:
// TODO optimization: some functions are deterministic, but we don't
if
(!
isDeterministic
())
{
// know (no setting for that)
return
false
;
return
false
;
}
else
{
// only if all parameters are deterministic as well
break
;
}
case
ExpressionVisitor
.
GET_DEPENDENCIES
:
case
ExpressionVisitor
.
GET_DEPENDENCIES
:
visitor
.
addDependency
(
functionAlias
);
visitor
.
addDependency
(
functionAlias
);
break
;
break
;
...
@@ -145,4 +151,8 @@ public class JavaFunction extends Expression implements FunctionCall {
...
@@ -145,4 +151,8 @@ public class JavaFunction extends Expression implements FunctionCall {
return
cost
;
return
cost
;
}
}
public
boolean
isDeterministic
()
{
return
functionAlias
.
isDeterministic
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论