提交 e89be84b 编写于 作者: H Heikki Linnakangas

Remove check for NOT NULLable column from ORCA translation of INSERT values.

When creating an ORCA plan for "INSERT ... (<col list>) VALUES (<values>)"
statement, the ORCA translator performed NULL checks for any columns not
listed in the column list. Nothing wrong with that per se, but we needed
to keep the error messages in sync, or we'd get regression test failures
caused by different messages. To simplify that, remove the check from
ORCA translator, and rely on the execution time check.

We bumped into this while working on the 9.3 merge, because 9.3 added
DETAIL to the error message in executor:

postgres=# create table notnulls (a text NOT NULL, b text NOT NULL);
CREATE TABLE
postgres=# insert into notnulls (a) values ('x');
ERROR:  null value in column "b" violates not-null constraint
postgres=# insert into notnulls (a,b) values ('x', NULL);
ERROR:  null value in column "b" violates not-null constraint  (seg2 127.0.0.1:40002 pid=26547)
DETAIL:  Failing row contains (x, null).

Doing this now will avoid that inconsistency in the merge.

One little difference with this is that EXPLAIN on an insert like above
now works, and you only get the error when you try to execute it. Before,
with ORCA, even EXPLAIN would throw the error.
上级 d94bebb5
......@@ -2260,8 +2260,7 @@ CTranslatorUtils::HasProjElem
//
// @doc:
// Create a DXL project element node with a Const NULL of type provided
// by the column descriptor. The function raises an exception if the
// column is not nullable.
// by the column descriptor.
//
//---------------------------------------------------------------------------
CDXLNode *
......@@ -2277,11 +2276,6 @@ CTranslatorUtils::CreateDXLProjElemConstNULL
GPOS_ASSERT(!md_col->IsSystemColumn());
const WCHAR *col_name = md_col->Mdname().GetMDName()->GetBuffer();
if (!md_col->IsNullable())
{
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLNotNullViolation, col_name);
}
ULONG colid = pidgtorCol->next_id();
CDXLNode *dxl_project_element = CreateDXLProjElemConstNULL(mp, md_accessor, md_col->MdidType(), colid, col_name);
......
......@@ -199,6 +199,7 @@ NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'col1'
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO nulltest DEFAULT VALUES;
ERROR: null value in column "col3" violates not-null constraint
DETAIL: Failing row contains (null, null, null, null, null).
INSERT INTO nulltest values ('a', 'b', 'c', 'd', 'c'); -- Good
insert into nulltest values ('a', 'b', 'c', 'd', NULL);
ERROR: domain dcheck does not allow null values
......
......@@ -541,7 +541,8 @@ SELECT relname, d.* FROM ONLY d, pg_class where d.tableoid = pg_class.oid;
CREATE TEMP TABLE z (b TEXT, PRIMARY KEY(aa, b)) inherits (a);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "z_pkey" for table "z"
INSERT INTO z VALUES (NULL, 'text'); -- should fail
ERROR: null value in column "b" violates not-null constraint
ERROR: null value in column "dummy" violates not-null constraint (seg1 172.17.0.2:25433 pid=366731)
DETAIL: Failing row contains (null, text, null).
-- Check UPDATE with inherited target and an inherited source table
create temp table foo(f1 int, f2 int);
create temp table foo2(f3 int) inherits (foo);
......
......@@ -312,6 +312,7 @@ SELECT COUNT(*) FROM dml_ao_check_s;
INSERT INTO dml_ao_check_s values(default,1,'nn',1.0000);
ERROR: null value in column "a" violates not-null constraint (seg0 127.0.0.1:40000 pid=18972)
DETAIL: Failing row contains (null, 1, nn, 1.0000).
SELECT COUNT(*) FROM dml_ao_check_s;
count
-------
......@@ -1159,6 +1160,7 @@ SELECT COUNT(*) FROM dml_co_check_s;
INSERT INTO dml_co_check_s values(default,1,'nn',1.0000);
ERROR: null value in column "a" violates not-null constraint (seg0 127.0.0.1:40000 pid=18972)
DETAIL: Failing row contains (null, 1, nn, 1.0000).
SELECT COUNT(*) FROM dml_co_check_s;
count
-------
......@@ -2028,6 +2030,7 @@ SELECT COUNT(*) FROM dml_heap_check_s;
INSERT INTO dml_heap_check_s values(default,1,'nn',1.0000);
ERROR: null value in column "a" violates not-null constraint (seg0 127.0.0.1:40000 pid=18972)
DETAIL: Failing row contains (null, 1, nn, 1.0000).
SELECT COUNT(*) FROM dml_heap_check_s;
count
-------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册