提交 d5b46ed8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 380: ALTER TABLE ADD FOREIGN KEY with an explicit index didn't verify the…

Issue 380: ALTER TABLE ADD FOREIGN KEY with an explicit index didn't verify the index can be used, which would lead to a NullPointerException later on.
上级 e15bc041
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The wrong kind of exception (NullPointerException) was thrown in a UNION query
<ul><li>Issue 380: ALTER TABLE ADD FOREIGN KEY with an explicit index didn't verify
the index can be used, which would lead to a NullPointerException later on.
</li><li>The wrong kind of exception (NullPointerException) was thrown in a UNION query
with an incorrect ORDER BY expression.
</li><li>Issue 362: support LIMIT in UPDATE statements.
</li><li>Browser: if no default browser is set, Google Chrome is now used if available.
......
......@@ -199,7 +199,8 @@ public class AlterTableAddConstraint extends SchemaCommand {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
boolean isRefOwner = false;
if (refIndex != null && refIndex.getTable() == refTable) {
if (refIndex != null && refIndex.getTable() == refTable &&
canUseIndex(refIndex, refTable, refIndexColumns)) {
isRefOwner = true;
refIndex.getIndexType().setBelongsToConstraint(true);
} else {
......
......@@ -22,7 +22,7 @@ Inserts a new row / new rows into a table."
"Commands (DML)","UPDATE","
UPDATE tableName [ [ AS ] newTableAlias ]
SET { columnName = { DEFAULT | expression } } [,...]
[ WHERE expression ]
[ WHERE expression ] [ LIMIT expression ]
","
Updates data in a table."
"Commands (DML)","DELETE","
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test (id int not null, pid int);
> ok
create index idx_test_pid on test (pid);
> ok
alter table test add constraint fk_test foreign key (pid)
references test (id) index idx_test_pid;
> ok
insert into test values (2, null);
> ok
update test set pid = 1 where id = 2;
> ok
drop table test;
> ok
call cast('null' as uuid);
> exception
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论