Return-Path: <oracle-l-bounce@freelists.org>
X-Original-To: oracle-l@orafaq.com
Delivered-To: oracle-l@orafaq.com
Received: from puck1183.startdedicated.com (localhost [127.0.0.1])
 by puck1183.startdedicated.com (Postfix) with ESMTP id 8681B19615E7
 for <oracle-l@orafaq.com>; Mon, 10 Oct 2016 16:32:04 +0200 (CEST)
Received: from turing.freelists.org (turing.freelists.org [206.53.239.180])
 by puck1183.startdedicated.com (Postfix) with ESMTPS
 for <oracle-l@orafaq.com>; Mon, 10 Oct 2016 16:32:04 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 80D82306E2;
 Mon, 10 Oct 2016 10:32:03 -0400 (EDT)
X-Virus-Scanned: Debian amavisd-new at turing.freelists.org
Received: from turing.freelists.org ([127.0.0.1])
 by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id J64324e2EFQw; Mon, 10 Oct 2016 10:32:03 -0400 (EDT)
Received: from turing.freelists.org (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 5856E2FF32;
 Mon, 10 Oct 2016 10:31:50 -0400 (EDT)
Received: with ECARTIS (v1.0.0; list oracle-l); Mon, 10 Oct 2016 10:30:28 -0400 (EDT)
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 55DA52F66C
 for <oracle-l@freelists.org>; Mon, 10 Oct 2016 10:30:28 -0400 (EDT)
Received: from turing.freelists.org ([127.0.0.1])
 by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id itxCrvcNsQ3e for <oracle-l@freelists.org>;
 Mon, 10 Oct 2016 10:30:28 -0400 (EDT)
Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194])
 (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id B13322F5DD
 for <oracle-l@freelists.org>; Mon, 10 Oct 2016 10:30:25 -0400 (EDT)
Received: from mfilter28-d.gandi.net (mfilter28-d.gandi.net [217.70.178.159])
 by relay2-d.mail.gandi.net (Postfix) with ESMTP id 1BA77C5AA1
 for <oracle-l@freelists.org>; Mon, 10 Oct 2016 16:30:24 +0200 (CEST)
Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194])
 by mfilter28-d.gandi.net (mfilter28-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024)
 with ESMTP id LFTPzD4ecZ8n for <oracle-l@freelists.org>;
 Mon, 10 Oct 2016 16:30:22 +0200 (CEST)
X-Originating-IP: 209.85.214.42
Received: from mail-it0-f42.google.com (mail-it0-f42.google.com [209.85.214.42])
 (Authenticated sender: mailbox@pachot.net)
 by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id B70D3C5A79
 for <oracle-l@freelists.org>; Mon, 10 Oct 2016 16:30:21 +0200 (CEST)
Received: by mail-it0-f42.google.com with SMTP id e203so14827719itc.0
        for <oracle-l@freelists.org>; Mon, 10 Oct 2016 07:30:21 -0700 (PDT)
X-Gm-Message-State: AA6/9Rk/Ku3jhv3YopYmicBi2EqFe2jyk3A+MAvzJVzy3ihkr2vTyO/dA/ywMyPx5bVD+DeOwNtzUIDpxOTZew==
X-Received: by 10.36.155.84 with SMTP id o81mr11703619itd.90.1476109820212;
 Mon, 10 Oct 2016 07:30:20 -0700 (PDT)
MIME-Version: 1.0
References: <4812A130-901F-429D-AA1D-4CDB9DB20CB4@gmail.com>
 <CAA9w=EvH1x3dv-wuqb5YtHdUv9Z+7YQboez=W4Bt2v32V-yyyw@mail.gmail.com> <CE70217733273F49A8A162EE074F64D90150342E29@exmbx05.thus.corp>
In-Reply-To: <CE70217733273F49A8A162EE074F64D90150342E29@exmbx05.thus.corp>
From: Franck Pachot <franck@pachot.net>
Date: Mon, 10 Oct 2016 14:30:09 +0000
X-Gmail-Original-Message-ID: <CAK6ito06e5UTRwJy3w99qOyzf21PfDimAwSHYCB_hwE7EZiwzw@mail.gmail.com>
Message-ID: <CAK6ito06e5UTRwJy3w99qOyzf21PfDimAwSHYCB_hwE7EZiwzw@mail.gmail.com>
Subject: Re: strange constraint behavior
To: jonathan@jlcomp.demon.co.uk, oracle-l-freelists <oracle-l@freelists.org>
Content-Type: multipart/alternative; boundary=94eb2c06006c7bfa91053e8399dc
X-archive-position: 66442
X-ecartis-version: Ecartis v1.0.0
Sender: oracle-l-bounce@freelists.org
Errors-to: oracle-l-bounce@freelists.org
X-original-sender: franck@pachot.net
Precedence: normal
Reply-To: franck@pachot.net
List-help: <mailto:ecartis@freelists.org?Subject=help>
List-unsubscribe: <oracle-l-request@freelists.org?Subject=unsubscribe>
List-software: Ecartis version 1.0.0
List-Id: oracle-l <oracle-l.freelists.org>
X-List-ID: oracle-l <oracle-l.freelists.org>
List-subscribe: <oracle-l-request@freelists.org?Subject=subscribe>
List-owner: <mailto:mark.bobak@proquest.com>
List-post: <mailto:oracle-l@freelists.org>
List-archive: <http://www.freelists.org/archives/oracle-l>
X-list: oracle-l
--94eb2c06006c7bfa91053e8399dc
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi,
There's a patch for Bug 16791865  "ALTER TABLE .. add .. default '' not
null" executes without error
<https://support.oracle.com/epmos/faces/DocContentDisplay?id=3D16791865.8>
Regards,
Franck.

On Mon, Oct 10, 2016 at 4:27 PM Jonathan Lewis <jonathan@jlcomp.demon.co.uk=
>
wrote:

>
> Just tried it in 11.2.0.4 - you're right; and in the second one it's usin=
g
> the constraint to eliminate the predicate and excuting select count(*);
> "Fixed" in 12c where you get the funny error message about empty tables
> whether you try to add the column with default '' or default null.
>
>
> Funnier version of the test in 11g:
> SQL> get afiedt.buf
>   1* select count (*) from tt where flag is not null
> SQL> /
>
>   COUNT(*)
> ----------
>        100
>
> 1 row selected.
>
> SQL> create index tt_u1 on tt(flag);
>
> Index created.
>
> SQL> get afiedt.buf
>   1* select count (*) from tt where flag is not null
> SQL> /
>
>   COUNT(*)
> ----------
>          0
>
> 1 row selected.
>
>
> Create an index and the data vanishes (conversely, drop it and the data
> re-appears).
>
>
>
>
> Regards
> Jonathan Lewis
> http://jonathanlewis.wordpress.com
> @jloracle
> ------------------------------
> *From:* oracle-l-bounce@freelists.org [oracle-l-bounce@freelists.org] on
> behalf of Toon Koppelaars [toon.koppelaars@rulegen.com]
> *Sent:* 10 October 2016 15:13
> *To:* djeday84@gmail.com
> *Cc:* oracle-l-freelists
> *Subject:* Re: strange constraint behavior
>
> In your 1st query, very likely the optimizer has injected the constraint
> text 'FLAG IS NOT NULL' and through transitive closure it then generated =
a
> "NULL IS NOT NULL" filter predicate.
>
> If you show us the execution plan, we can verify this.
>
>
> On Mon, Oct 10, 2016 at 3:48 PM, Anton Bushmelev <djeday84@gmail.com>
> wrote:
>
> hello, look at new patch from developer and found strange construction,
> here I=E2=80=99ll try to reproduce what they want to do:
>
> create table tt as select level id from dual connect by level <=3D100;
> alter table tt add flag varchar2(50)  default '' not null ;
> Table altered.
>
> select dump (flag,8 ) as dmp from tt ;
>
> DMP
> ----------
> NULL
> NULL
> =E2=80=A6..
> NULL
>
>
>  select count (*) from tt where flag is null;
>
>   COUNT(*)
> ----------
>          0
>
> select count (*) from tt where flag is not null;
>
>   COUNT(*)
> ----------
>        100
>
>
> How it is possible ? =3D)))
>
>
> ps: if I add default *null, *then all goes well:
>
>  alter table tt add flag varchar2(50)  default null not null ;
> alter table tt add flag varchar2(50)  default null not null
>             *
> ERROR at line 1:
> ORA-01758: table must be empty to add mandatory (NOT NULL) column
>
> create table tt as select level id from dual connect by level <=3D100;
>  alter table tt add flag varchar2(50)  default null not null ;
> alter table tt add flag varchar2(50)  default null not null
>             *
> ERROR at line 1:
> ORA-01758: table must be empty to add mandatory (NOT NULL) column
>
>
> ps: sorry for my English
>
>
>
>
>
> --
> Toon Koppelaars
> RuleGen BV
> Toon.Koppelaars@RuleGen.com
> www.RuleGen.com
> TheHelsinkiDeclaration.blogspot.com
>
> (co)Author: "Applied Mathematics for Database Professionals"
> www.rulegen.com/am4dp-backcover-text
>

--94eb2c06006c7bfa91053e8399dc
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<div>There&#39;s a patch for=C2=A0<a href=3D"https://su=
pport.oracle.com/epmos/faces/DocContentDisplay?id=3D16791865.8">Bug 1679186=
5 =C2=A0&quot;ALTER TABLE .. add .. default &#39;&#39; not null&quot; execu=
tes without error</a></div><div>Regards,</div><div>Franck.</div></div><br><=
div class=3D"gmail_quote"><div dir=3D"ltr">On Mon, Oct 10, 2016 at 4:27 PM =
Jonathan Lewis &lt;<a href=3D"mailto:jonathan@jlcomp.demon.co.uk">jonathan@=
jlcomp.demon.co.uk</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div class=3D"gmail_msg">
<div style=3D"direction:ltr;font-family:Tahoma;color:#000000;font-size:10pt=
" class=3D"gmail_msg"><br class=3D"gmail_msg">
Just tried it in 11.2.0.4 - you&#39;re right; and in the second one it&#39;=
s using the constraint to eliminate the predicate and excuting select count=
(*);=C2=A0 &quot;Fixed&quot; in 12c where you get the funny error message a=
bout empty tables whether you try to add the column with
 default &#39;&#39; or default null.<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
Funnier version of the test in 11g:<br class=3D"gmail_msg">
SQL&gt; get afiedt.buf<br class=3D"gmail_msg">
=C2=A0 1* select count (*) from tt where flag is not null<br class=3D"gmail=
_msg">
SQL&gt; /<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
=C2=A0 COUNT(*)<br class=3D"gmail_msg">
----------<br class=3D"gmail_msg">
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 100<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
1 row selected.<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
SQL&gt; create index tt_u1 on tt(flag);<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
Index created.<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
SQL&gt; get afiedt.buf<br class=3D"gmail_msg">
=C2=A0 1* select count (*) from tt where flag is not null<br class=3D"gmail=
_msg">
SQL&gt; /<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
=C2=A0 COUNT(*)<br class=3D"gmail_msg">
----------<br class=3D"gmail_msg">
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
1 row selected.<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
Create an index and the data vanishes (conversely, drop it and the data re-=
appears).<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
<div class=3D"gmail_msg">
<div class=3D"m_-1535926233253472748BodyFragment gmail_msg"><font size=3D"2=
" class=3D"gmail_msg"><span style=3D"font-size:10pt" class=3D"gmail_msg">
<div class=3D"m_-1535926233253472748PlainText gmail_msg">=C2=A0=C2=A0 <br c=
lass=3D"gmail_msg">
Regards<br class=3D"gmail_msg">
Jonathan Lewis<br class=3D"gmail_msg">
<a href=3D"http://jonathanlewis.wordpress.com" class=3D"gmail_msg" target=
=3D"_blank">http://jonathanlewis.wordpress.com</a><br class=3D"gmail_msg">
@jloracle <br class=3D"gmail_msg">
</div>
</span></font></div>
</div>
<div style=3D"font-family:Times New Roman;color:#000000;font-size:16px" cla=
ss=3D"gmail_msg">
<hr class=3D"gmail_msg">
<div id=3D"m_-1535926233253472748divRpF185631" style=3D"direction:ltr" clas=
s=3D"gmail_msg"><font size=3D"2" color=3D"#000000" face=3D"Tahoma" class=3D=
"gmail_msg"><b class=3D"gmail_msg">From:</b> <a href=3D"mailto:oracle-l-bou=
nce@freelists.org" class=3D"gmail_msg" target=3D"_blank">oracle-l-bounce@fr=
eelists.org</a> [<a href=3D"mailto:oracle-l-bounce@freelists.org" class=3D"=
gmail_msg" target=3D"_blank">oracle-l-bounce@freelists.org</a>] on behalf o=
f Toon Koppelaars [<a href=3D"mailto:toon.koppelaars@rulegen.com" class=3D"=
gmail_msg" target=3D"_blank">toon.koppelaars@rulegen.com</a>]<br class=3D"g=
mail_msg">
<b class=3D"gmail_msg">Sent:</b> 10 October 2016 15:13<br class=3D"gmail_ms=
g">
<b class=3D"gmail_msg">To:</b> <a href=3D"mailto:djeday84@gmail.com" class=
=3D"gmail_msg" target=3D"_blank">djeday84@gmail.com</a><br class=3D"gmail_m=
sg">
<b class=3D"gmail_msg">Cc:</b> oracle-l-freelists<br class=3D"gmail_msg">
<b class=3D"gmail_msg">Subject:</b> Re: strange constraint behavior<br clas=
s=3D"gmail_msg">
</font><br class=3D"gmail_msg">
</div></div></div></div><div class=3D"gmail_msg"><div style=3D"direction:lt=
r;font-family:Tahoma;color:#000000;font-size:10pt" class=3D"gmail_msg"><div=
 style=3D"font-family:Times New Roman;color:#000000;font-size:16px" class=
=3D"gmail_msg">
<div class=3D"gmail_msg"></div>
<div class=3D"gmail_msg">
<div dir=3D"ltr" class=3D"gmail_msg">In your 1st query, very likely the opt=
imizer has injected the constraint text &#39;FLAG IS NOT NULL&#39; and thro=
ugh transitive closure it then generated a &quot;NULL IS NOT NULL&quot; fil=
ter predicate.
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">If you show us the execution plan, we can verify t=
his.</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
</div>
<div class=3D"gmail_extra gmail_msg"><br class=3D"gmail_msg">
<div class=3D"gmail_quote gmail_msg">On Mon, Oct 10, 2016 at 3:48 PM, Anton=
 Bushmelev <span dir=3D"ltr" class=3D"gmail_msg">
&lt;<a href=3D"mailto:djeday84@gmail.com" class=3D"gmail_msg" target=3D"_bl=
ank">djeday84@gmail.com</a>&gt;</span> wrote:<br class=3D"gmail_msg">
<blockquote class=3D"gmail_quote gmail_msg" style=3D"margin:0 0 0 .8ex;bord=
er-left:1px #ccc solid;padding-left:1ex">
<div style=3D"word-wrap:break-word" class=3D"gmail_msg">
<div class=3D"gmail_msg">hello, look at new patch from developer and found =
strange construction, here I=E2=80=99ll try to reproduce what they want to =
do:</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">create table tt as select level id from dual conne=
ct by level &lt;=3D100;=C2=A0</div>
<div class=3D"gmail_msg">alter table tt add flag varchar2(50) =C2=A0default=
 &#39;&#39; not null ;</div>
<div class=3D"gmail_msg">Table altered.</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">select dump (flag,8 ) as dmp from tt ;</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">DMP</div>
<div class=3D"gmail_msg">----------</div>
<div class=3D"gmail_msg">NULL</div>
<div class=3D"gmail_msg">NULL</div>
<div class=3D"gmail_msg">=E2=80=A6..</div>
<div class=3D"gmail_msg">NULL</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">=C2=A0select count (*) from tt where flag is null;=
</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">=C2=A0 COUNT(*)</div>
<div class=3D"gmail_msg">----------</div>
<div class=3D"gmail_msg">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">select count (*) from tt where flag is not null;</=
div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">=C2=A0 COUNT(*)</div>
<div class=3D"gmail_msg">----------</div>
<div class=3D"gmail_msg">=C2=A0 =C2=A0 =C2=A0 =C2=A0100</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">How it is possible ? =3D)))</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">ps: if I add default <b class=3D"gmail_msg">null, =
</b>then all goes well:</div>
<div class=3D"gmail_msg">=C2=A0</div>
<div class=3D"gmail_msg">=C2=A0alter table tt add flag varchar2(50) =C2=A0d=
efault null not null ;</div>
<div class=3D"gmail_msg">alter table tt add flag varchar2(50) =C2=A0default=
 null not null</div>
<div class=3D"gmail_msg">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *</div>
<div class=3D"gmail_msg">ERROR at line 1:</div>
<div class=3D"gmail_msg">ORA-01758: table must be empty to add mandatory (N=
OT NULL) column=C2=A0</div>
<div class=3D"gmail_msg">
<div class=3D"gmail_msg">=C2=A0</div>
<div class=3D"gmail_msg">create table tt as select level id from dual conne=
ct by level &lt;=3D100;</div>
<div class=3D"gmail_msg">=C2=A0alter table tt add flag varchar2(50) =C2=A0d=
efault null not null ;</div>
<div class=3D"gmail_msg">alter table tt add flag varchar2(50) =C2=A0default=
 null not null</div>
<div class=3D"gmail_msg">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *</div>
<div class=3D"gmail_msg">ERROR at line 1:</div>
<div class=3D"gmail_msg">ORA-01758: table must be empty to add mandatory (N=
OT NULL) column</div>
</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
<div class=3D"gmail_msg">ps: sorry for my English</div>
<div class=3D"gmail_msg">=C2=A0 =C2=A0 =C2=A0 =C2=A0</div>
</div>
</blockquote>
</div>
<br class=3D"gmail_msg">
<br clear=3D"all" class=3D"gmail_msg">
<div class=3D"gmail_msg"><br class=3D"gmail_msg">
</div>
-- <br class=3D"gmail_msg">
<div class=3D"m_-1535926233253472748gmail_signature gmail_msg">Toon Koppela=
ars<br class=3D"gmail_msg">
RuleGen BV<br class=3D"gmail_msg">
Toon.Koppelaars@RuleGen.com<br class=3D"gmail_msg">
<a href=3D"http://www.RuleGen.com" class=3D"gmail_msg" target=3D"_blank">ww=
w.RuleGen.com</a><br class=3D"gmail_msg">
<a href=3D"http://TheHelsinkiDeclaration.blogspot.com" class=3D"gmail_msg" =
target=3D"_blank">TheHelsinkiDeclaration.blogspot.com</a><br class=3D"gmail=
_msg">
<br class=3D"gmail_msg">
(co)Author: &quot;Applied Mathematics for Database Professionals&quot;<br c=
lass=3D"gmail_msg">
<a href=3D"http://www.rulegen.com/am4dp-backcover-text" class=3D"gmail_msg"=
 target=3D"_blank">www.rulegen.com/am4dp-backcover-text</a><br class=3D"gma=
il_msg">
</div>
</div>
</div>
</div></div></div></blockquote></div>

--94eb2c06006c7bfa91053e8399dc--
--
http://www.freelists.org/webpage/oracle-l


