You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Brett Bergquist (Created) (JIRA)" <ji...@apache.org> on 2012/04/01 01:08:28 UTC

[jira] [Created] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
----------------------------------------------------------------------------------------------------------------------

                 Key: DERBY-5681
                 URL: https://issues.apache.org/jira/browse/DERBY-5681
             Project: Derby
          Issue Type: Bug
          Components: Store
    Affects Versions: 10.8.2.2
            Reporter: Brett Bergquist


If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.

Here is how to get it to happen:

set schema app;

CREATE TABLE TEST_TAB_1
(
    ID INTEGER PRIMARY KEY NOT NULL
);

CREATE TABLE TEST_TAB_2
(
   ID INTEGER PRIMARY KEY NOT NULL
);

ALTER TABLE TEST_TAB_2
ADD CONSTRAINT TEST_TAB_2_FK_1
FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);

insert into app.TEST_TAB_1 values (1);
insert into test_tab_2 values(1);

call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);

select
c.TABLEID,
c.CONGLOMERATENUMBER,
c.CONGLOMERATENAME,
c.ISINDEX,
c.ISCONSTRAINT,
c.CONGLOMERATEID,
t.TABLEID,
t.TABLENAME,
t.TABLETYPE,
s.STATID,
s.REFERENCEID,
s.TABLEID,
s.CREATIONTIMESTAMP,
s.TYPE,
s.VALID,
s.COLCOUNT,
CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;

-- At this point there are two statistic rows

TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1

-- Now drop the constraint

alter table TEST_TAB_2
drop constraint TEST_TAB_2_FK_1;

select
c.TABLEID,
c.CONGLOMERATENUMBER,
c.CONGLOMERATENAME,
c.ISINDEX,
c.ISCONSTRAINT,
c.CONGLOMERATEID,
t.TABLEID,
t.TABLENAME,
t.TABLETYPE,
s.STATID,
s.REFERENCEID,
s.TABLEID,
s.CREATIONTIMESTAMP,
s.TYPE,
s.VALID,
s.COLCOUNT,
CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;

-- There are still two statistic rows

TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1

-- Add another row

insert into app.TEST_TAB_1 values (2);
insert into test_tab_2 values(2);

-- Update the statistics

call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);

select
c.TABLEID,
c.CONGLOMERATENUMBER,
c.CONGLOMERATENAME,
c.ISINDEX,
c.ISCONSTRAINT,
c.CONGLOMERATEID,
t.TABLEID,
t.TABLENAME,
t.TABLETYPE,
s.STATID,
s.REFERENCEID,
s.TABLEID,
s.CREATIONTIMESTAMP,
s.TYPE,
s.VALID,
s.COLCOUNT,
CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;

-- There are still two rows but now one show 1 row and one shows 2 rows

TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2

-- Add the constraint back on

ALTER TABLE TEST_TAB_2
ADD CONSTRAINT TEST_TAB_2_FK_1
FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);

-- Insert another row

insert into app.TEST_TAB_1 values (3);
insert into test_tab_2 values(3);

-- Update the statistics

call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);

select
c.TABLEID,
c.CONGLOMERATENUMBER,
c.CONGLOMERATENAME,
c.ISINDEX,
c.ISCONSTRAINT,
c.CONGLOMERATEID,
t.TABLEID,
t.TABLENAME,
t.TABLETYPE,
s.STATID,
s.REFERENCEID,
s.TABLEID,
s.CREATIONTIMESTAMP,
s.TYPE,
s.VALID,
s.COLCOUNT,
CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;

-- Now there are 3 rows

TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3

Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Fix Version/s: 10.4.2.1
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Fix Version/s: 10.5.3.1
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Kristian Waagan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kristian Waagan updated DERBY-5681:
-----------------------------------

    Attachment: derby-5681-3a-test.diff

Attaching patch 3a, which makes the test testIndexAndColumnNamedStatistics less sensitive to statistics created by other tests.

Committed to trunk with revision 1341002.
As part of DERBY-3790 I will also add cleanup code to testDisposableStatsEagerness.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.3.3.1, 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt, derby-5681-3a-test.diff
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13255743#comment-13255743 ] 

Mamta A. Satoor commented on DERBY-5681:
----------------------------------------

I am debugging this jira. Not finished yet but it may be related to the changes that went in for  DERBY-3299 (Uniqueness violation error (23505) occurs after dropping a PK constraint if there exists a foreign key on the same columns). Will debug further and post the finidings. I think this is yet another case where same backing index is being used by multiple constraints.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY5681_patch1_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Comment Edited] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Kristian Waagan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13280124#comment-13280124 ] 

Kristian Waagan edited comment on DERBY-5681 at 5/21/12 2:24 PM:
-----------------------------------------------------------------

Attaching patch 3a, which makes the test testIndexAndColumnNamedStatistics less sensitive to statistics created by other tests.

Committed to trunk with revision 1341002.
Cleanup code in testDisposableStatsEagerness was added as part of addressing DERBY-5774.
                
      was (Author: kristwaa):
    Attaching patch 3a, which makes the test testIndexAndColumnNamedStatistics less sensitive to statistics created by other tests.

Committed to trunk with revision 1341002.
As part of DERBY-3790 I will also add cleanup code to testDisposableStatsEagerness.
                  
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.3.3.1, 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt, derby-5681-3a-test.diff
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Fix Version/s: 10.9.0.0
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Fix Version/s: 10.8.2.3
                   10.7.1.4
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13277040#comment-13277040 ] 

Mamta A. Satoor commented on DERBY-5681:
----------------------------------------

Have backported the changes to 10.4 but in trunk , for this jira, we added some tests which use upgrade statistics procedure but since that procedure doesn't exist in 10.4 and before, they couldn't be backported to 10.4 without changes. In 10.4, I added those tests to a new class, namely Derby5681Test.java without using update statisitcs procedure. But, because of the absence of update statisitcs procedure and DERBY-5702, we can't quite have a statistics row for a constraint which shares a backing index in 10.4 and before. The test in 10.4 will just have a test to drop constraint(that shares a backing index with another constraint) and show that it doesn't break anything. Once DERBY-5702 is fixed and backported to 10.4 and before, we will have a statistics row for a constraint which shares a backing index and we will be able to show that as a fix of this jira, that statistics row will get dropped when the constraint is dropped.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor resolved DERBY-5681.
------------------------------------

    Resolution: Fixed
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.3.3.1, 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13280305#comment-13280305 ] 

Mamta A. Satoor commented on DERBY-5681:
----------------------------------------

Kristian, thanks for making the test more independent of other tests.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.3.3.1, 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt, derby-5681-3a-test.diff
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13257955#comment-13257955 ] 

Mamta A. Satoor commented on DERBY-5681:
----------------------------------------

While going through the code, I found following comment in CreateIndexConstantAction about what will determine if a backing index will be shared by multiple constraints.

			/* The conditions which allow an index to share an existing
			 * conglomerate are as follows:
			 *
			 * 1. the set of columns (both key and include columns) and their 
			 *  order in the index is the same as that of an existing index AND 
			 *
			 * 2. the ordering attributes are the same AND 
			 *
			 * 3. one of the following is true:
			 *    a) the existing index is unique, OR
			 *    b) the existing index is non-unique with uniqueWhenNotNulls
			 *       set to TRUE and the index being created is non-unique, OR
			 *    c) both the existing index and the one being created are
			 *       non-unique and have uniqueWithDuplicateNulls set to FALSE.
			 */ 

                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY5681_patch1_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Attachment: DERBY5681_patch2_diff.txt

Attaching a patch which fixes the problem associated with this jira. Basically, when two constraints share the same backing index, we conditionally dropped the statistics. Instead, this fix will make sure that the statistics are always dropped even if the underneath backing index is still valid(and hence won't be dropped and recreated) for other constraints. I ran derbyall and junit suite and they both ran fine with no errors. Please let me know if there is any feedback on the patch. I have also added few tests for the issue.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor reassigned DERBY-5681:
--------------------------------------

    Assignee: Mamta A. Satoor
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Comment Edited] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13277040#comment-13277040 ] 

Mamta A. Satoor edited comment on DERBY-5681 at 5/16/12 7:33 PM:
-----------------------------------------------------------------

Have backported the changes to 10.4 but in trunk , for this jira, we added some tests which use upgrade statistics procedure but since that procedure doesn't exist in 10.4 and before, the new tests for this jira from trunk couldn't be backported to 10.4 without changes. In 10.4, I added those tests to a new class, namely Derby5681Test.java and these tests donot use update statisitcs procedure. But, because of the absence of update statisitcs procedure and DERBY-5702, we can't quite have a statistics row for a constraint which shares a backing index in 10.4 and before. The test in 10.4 will just have a test to drop constraint(that shares a backing index with another constraint) and show that it doesn't break anything. Once DERBY-5702 is fixed and backported to 10.4 and before, we will have a statistics row for a constraint which shares a backing index and we will be able to show that as a fix of this jira, that statistics row will get dropped when the constraint is dropped.

                
      was (Author: mamtas):
    Have backported the changes to 10.4 but in trunk , for this jira, we added some tests which use upgrade statistics procedure but since that procedure doesn't exist in 10.4 and before, they couldn't be backported to 10.4 without changes. In 10.4, I added those tests to a new class, namely Derby5681Test.java without using update statisitcs procedure. But, because of the absence of update statisitcs procedure and DERBY-5702, we can't quite have a statistics row for a constraint which shares a backing index in 10.4 and before. The test in 10.4 will just have a test to drop constraint(that shares a backing index with another constraint) and show that it doesn't break anything. Once DERBY-5702 is fixed and backported to 10.4 and before, we will have a statistics row for a constraint which shares a backing index and we will be able to show that as a fix of this jira, that statistics row will get dropped when the constraint is dropped.
                  
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Fix Version/s: 10.3.3.1
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.3.3.1, 10.4.2.1, 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Fix Version/s: 10.6.2.3
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13258455#comment-13258455 ] 

Mamta A. Satoor commented on DERBY-5681:
----------------------------------------

If we go with patch DERBY5681_patch2_diff.txt, then it will be fine to backport it to earlier releases.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mike Matrigali (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mike Matrigali updated DERBY-5681:
----------------------------------

    Component/s: SQL

just changing the component, the problem is most likely in the drop constraint code in the sql layer of the system.  The storage layer does not
know anything about the sysstatistics catalog.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Issue & fix info: Patch Available,Repro attached  (was: Repro attached)
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13256838#comment-13256838 ] 

Mamta A. Satoor commented on DERBY-5681:
----------------------------------------

I debugged Derby code for this jira and found the problem to be in iapi.sql.dictionary.ConglomerateDescriptor:drop() method
One of the checks being made in this method is as follows
		if (congDescs.length == 1)
			dropConglom = true;
		else
		{
In case of this jira, we have multiple constraints sharing the same backing index and hence we go to the else code of the above if else code. In this code, based on some conditions, we check if we need to drop and recreate the backing index. I need to study this code further to see how we decide whether we should recreate a new backing index. But it appears, in our specific case, we do not drop and recreate the backing index and that might be the cause behind statistics not getting dropped when foreign constraint is dropped. I will post more as I find more info.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY5681_patch1_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Fix Version/s:     (was: 10.5.3.1)
                   10.5.3.2
    
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>             Fix For: 10.5.3.2, 10.6.2.3, 10.7.1.4, 10.8.2.3, 10.9.0.0
>
>         Attachments: DERBY5681_patch1_diff.txt, DERBY5681_patch2_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5681) When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed

Posted by "Mamta A. Satoor (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5681:
-----------------------------------

    Attachment: DERBY5681_patch1_diff.txt

I have added some test cases which are attached as a patch to this jira(DERBY5681_patch1_diff.txt)

I am seeing left over statistics row for the test case provided by Brett in this jira in my junit test as well but Unique key on nullable and non-nullable column and primary key constraints are working fine ie no left over statistics after those constraints are dropped.
                
> When a foreign key constraint on a table is dropped, the associated statistics row for the conglomerate is not removed
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5681
>                 URL: https://issues.apache.org/jira/browse/DERBY-5681
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Store
>    Affects Versions: 10.8.2.2
>            Reporter: Brett Bergquist
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY5681_patch1_diff.txt
>
>
> If you drop the foreign key constraint for a table, the statistics row does not get removed.   This affects the indexStat daemon because it now finds these statistics row which always appear as out of date, causing an update to be scheduled.
> Here is how to get it to happen:
> set schema app;
> CREATE TABLE TEST_TAB_1
> (
>     ID INTEGER PRIMARY KEY NOT NULL
> );
> CREATE TABLE TEST_TAB_2
> (
>    ID INTEGER PRIMARY KEY NOT NULL
> );
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> insert into app.TEST_TAB_1 values (1);
> insert into test_tab_2 values(1);
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- At this point there are two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Now drop the constraint
> alter table TEST_TAB_2
> drop constraint TEST_TAB_2_FK_1;
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two statistic rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       05278254-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.628 I       true    1       numunique= 1 numrows= 1
> -- Add another row
> insert into app.TEST_TAB_1 values (2);
> insert into test_tab_2 values(2);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- There are still two rows but now one show 1 row and one shows 2 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       18438274-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:41:19.164 I       true    1       numunique= 2 numrows= 2
> -- Add the constraint back on
> ALTER TABLE TEST_TAB_2
> ADD CONSTRAINT TEST_TAB_2_FK_1
> FOREIGN KEY (ID) REFERENCES TEST_TAB_1(ID);
> -- Insert another row
> insert into app.TEST_TAB_1 values (3);
> insert into test_tab_2 values(3);
> -- Update the statistics
> call syscs_util.syscs_update_statistics('APP', 'TEST_TAB_2', null);
> select
> c.TABLEID,
> c.CONGLOMERATENUMBER,
> c.CONGLOMERATENAME,
> c.ISINDEX,
> c.ISCONSTRAINT,
> c.CONGLOMERATEID,
> t.TABLEID,
> t.TABLENAME,
> t.TABLETYPE,
> s.STATID,
> s.REFERENCEID,
> s.TABLEID,
> s.CREATIONTIMESTAMP,
> s.TYPE,
> s.VALID,
> s.COLCOUNT,
> CAST(STATISTICS AS VARCHAR(40)) as STATISTICS
> from sys.SYSCONGLOMERATES c join sys.SYSTABLES t on c.TABLEID = t.TABLEID join sys.SYSSTATISTICS s on s.TABLEID = t.TABLEID
> where t.TABLENAME = 'TEST_TAB_2' and c.ISINDEX = false;
> -- Now there are 3 rows
> TABLEID CONGLOMERATENUMBER      CONGLOMERATENAME        ISINDEX ISCONSTRAINT    CONGLOMERATEID  TABLEID TABLENAME       TABLETYPE       STATID  REFERENCEID     TABLEID CREATIONTIMESTAMP       TYPE    VALID   COLCOUNT        STATISTICS
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       edbc8255-0136-6999-c1b4-000065089f97    55410238-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:36:49.629 I       true    1       numunique= 1 numrows= 1
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       45eb02e8-0136-6999-c1b4-000065089f97    63454207-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.211 I       true    1       numunique= 3 numrows= 3
> 84490209-0136-6999-c1b4-000065089f97    348432  84490209-0136-6999-c1b4-000065089f97    false   false   cccb420a-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    TEST_TAB_2      T       0ea502e9-0136-6999-c1b4-000065089f97    7ab90278-0136-6999-c1b4-000065089f97    84490209-0136-6999-c1b4-000065089f97    2012-03-31 17:46:00.212 I       true    1       numunique= 3 numrows= 3
> Note that dropping that recreating the constraint or compressing the table does not fix the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira