[ 
https://issues.apache.org/jira/browse/TRAFODION-1678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15045342#comment-15045342
 ] 

David Wayne Birdsall commented on TRAFODION-1678:
-------------------------------------------------

There are two bugs that combine to produce the failure. Fixing either of them 
removes the failure.

1. When executing SHOWCONTROL and SHOWTRANSACTION, we are going through a 
function CmpDescribe in sqlcomp/CmpDescribe.cpp. Early in this function, it 
sets the INTERNAL_QUERY_FROM_EXEUTIL bit in the SqlParser_Flags. There is code 
at the end of the method to reset it, but unfortunately we take a "return" from 
the middle of the method instead so it is never reset. At the end of 
SHOWCONTROL ALL and SHOWTRANSACTION, then, this bit is set in the 
SqlParser_Flags.

When DROP SCHEMA is compiled, the binder code in DDLExpr::bindNode 
(optimizer/RelExeUtil.cpp) checks this flag and if not set, leaves its 
hbaseDDLNoUserXn_ member as FALSE. But that causes the code generator to label 
the statement as requiring a transaction. So, one is started at run-time. DROP 
SCHEMA cannot run in a transaction, however. So, transaction state gets goofed 
up as we drop the tables in the schema. Oddly, just having one table in the 
schema (mytable) doesn't seem to cause indigestion, but having three tables 
(mytable, sb_histograms and sb_histogram_intervals) does, yielding the TMF 
error 97. The last two tables are created by UPDATE STATISTICS. 

So the root cause is the incorrect setting of the SqlParser_Flags, caused by 
returns from the middle of a block of code that expects to reset this global at 
the end.

2. Early in DROP SCHEMA processing (well, processing of any statement), both 
sqlci and Trafci go through CliStatement::prepare2 to prepare the statement. 
They take a copy of parser flags from the CLI context object and pass that to 
CmpContext::compileDirect (arkcmp/CmpContext.cpp). That method in turn calls 
Set_SqlParser_Flags.

In sqlci, the value passed is 0. In Trafci, the value passed is 0x400000, or 
ALLOW_SET_ONCE_DEFAULTS. Now, Set_SqlParser_Flags has a peculiar semantic. If 
the parameter passed to it is non-zero, it ORs the parameter with the global 
SqlParser_Flags. If the parameter is zero, however, it sets the global to zero. 
So, in sqlci, the global gets set to zero, so the bug in CmpDescribe gets 
masked; the unintended INTERNAL_QUERY_FROM_EXEUTIL bit gets zeroed. But in 
Trafci, the global merely gets OR'd, and the INTERNAL_QUERY_FROM_EXEUTIL bit 
remains set.

It seems likely to me that the original authors of CmpContext::compileDirect 
intended to replace the value of SqlParser_Flags rather than ORing it. That can 
be accomplished by using Assign_SqlParser_Flags instead of Set_SqlParser_Flags.

> Some statements cause DROP SCHEMA to fail with DTM error 97
> -----------------------------------------------------------
>
>                 Key: TRAFODION-1678
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-1678
>             Project: Apache Trafodion
>          Issue Type: Bug
>          Components: sql-cmp
>    Affects Versions: 1.3-incubating
>            Reporter: David Wayne Birdsall
>            Assignee: David Wayne Birdsall
>             Fix For: 2.0-incubating
>
>
> The following script succeeds in sqlci, however in Trafci, the last two DROP 
> SCHEMA statements fail with DTM error 97:
> log mytest.log clear;
> create schema myschema_1;
> set schema myschema_1;
> create table mytable (a int, b int);
> -- update statistics for table mytable on every column;
> showcontrol all;
> drop schema myschema_1 cascade;
> create schema myschema_2;
> set schema myschema_2;
> create table mytable (a int, b int);
> update statistics for table mytable on every column;
> -- showcontrol all;
> drop schema myschema_2 cascade;
> create schema myschema_3;
> set schema myschema_3;
> create table mytable (a int, b int);
> update statistics for table mytable on every column;
> showcontrol all;
> drop schema myschema_3 cascade;
> create schema myschema_4;
> set schema myschema_4;
> create table mytable (a int, b int);
> update statistics for table mytable on every column;
> showtransaction;
> drop schema myschema_4 cascade;
> exit;
> Here is an example of the failing DROP SCHEMA statement taken from a Trafci 
> log:
> SQL>drop schema myschema_3 cascade;
> *** ERROR[8606] Transaction subsystem TMF returned error 97 on a commit 
> transaction. [2015-09-22 17:39:06]
> The "drop schema myschema_4 cascade" fails similarly.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to