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

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

I understand the cause of the problem. Not sure of the fix yet.

The UCASE/UPPER/UPSHIFT calls are converted to CAST nodes in the compiler 
(probably in the Binder), because the column is already upshifted. So, the join 
predicate is rewritten to CAST(T1.C1) = CAST(T2.C1). At code generation time 
(method HashJoin :: codeGen), we call preCodeGen on the join expression. Method 
Cast :: preCodeGen in particular notices that the Cast node does nothing and 
discards it, returning the child. This has the effect of rewriting the join 
predicate as T1.C1 = T2.C1. Unfortunately, though, we have already generated 
the children of the join, and their characteristic outputs contain the CAST 
expression, not the naked column reference. So, when we try to generate the 
join expression, the value is not available in the Map Table, which results in 
a generator assertion failure.

This seems to be a general issue: Any preCodeGen method in the ItemExpr 
hierarchy that can change the ValueId of the root node of an expression may 
fall prey to this kind of issue. So I'm not quite sure how to fix it.

Some possible alternatives are:
 # Eliminate the opportunity for these kinds of rewrites earlier in the game, 
before characteristic outputs are computed.
 # Change the preCodeGen logic to take into account the available valueIds 
before performing a rewrite.

In the specific case of Cast :: preCodeGen, it might make sense to simply 
delete the code that throws away the Cast node. It is likely that PCode 
generation and native expression generation both already have move 
optimizations that would optimize away the extra move implied by the Cast.

> Select of UPPER on upshifted column in join predicate cores
> -----------------------------------------------------------
>
>                 Key: TRAFODION-3018
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-3018
>             Project: Apache Trafodion
>          Issue Type: Bug
>          Components: sql-cmp
>    Affects Versions: 2.3
>            Reporter: David Wayne Birdsall
>            Assignee: David Wayne Birdsall
>            Priority: Major
>
> The following script reproduces the problem. First create the table and 
> populate it:
> drop table if exists mytable cascade;
> create table mytable (
> val int,
> c1 char(1) upshift,
> c2 char(1)
> );
> insert into mytable values (1, 'a', 'a');
> select * from mytable;
> If we now do any of the following SELECTs, we'll get an internal error on 
> release builds or a core on debug builds:
> select t1.val from mytable t1, mytable t2 where UCASE(t1.c1) = UCASE(t2.c1);
> select t1.val from mytable t1, mytable t2 where UPPER(t1.c1) = UPPER(t2.c1);
> select t1.val from mytable t1, mytable t2 where UPSHIFT(t1.c1) = 
> UPSHIFT(t2.c1);
> The first several frames on the core stack trace look like:
> (gdb) bt
> #0 0x00007ffff511a495 in raise () from /lib64/libc.so.6
> #1 0x00007ffff511bc75 in abort () from /lib64/libc.so.6
> #2 0x00007fffec50986d in GeneratorAbort (file=
>  0x7fffec68fce1 "../generator/Generator.cpp", line=2655, message=
>  0x7ffffffe8dc0 "\nValueId 7 (TRAFODION.SCH.MYTABLE.C1...) not found in 
> MapTable 0x7ffffffeb460") at ../generator/Generator.cpp:3029
> #3 0x00007fffec508caa in Generator::getMapInfo (this=0x7ffffffeb460, value_id=
>  ..., mapTable=0x0) at ../generator/Generator.cpp:2655
> #4 0x00007fffec5093a7 in Generator::getAttr (this=0x7ffffffeb460, ie=
>  0x7fffd300ac80) at ../generator/Generator.cpp:2876
> #5 0x00007fffec551e37 in ItemExpr::codegen_and_set_attributes (this=
>  0x7fffd09fd860, generator=0x7ffffffeb460, attr=0x7fffd0a015b8, num_attrs=3)
>  at ../generator/GenItemExpr.cpp:127
> #6 0x00007fffec52e2c8 in ExpGenerator::genItemExpr (this=0x7fffd09e2d08, 
>  item_expr=0x7fffd09fd860, out_attr=0x7ffffffe90a0, num_attrs=3, gen_child=
>  -1) at ../generator/GenExpGenerator.cpp:5389
> #7 0x00007fffec553920 in BiRelat::codeGen (this=0x7fffd09fd860, generator=
>  0x7ffffffeb460) at ../generator/GenItemExpr.cpp:560
> #8 0x00007fffec5598b1 in BoolResult::codeGen (this=0x7fffd09fe028, generator=
>  0x7ffffffeb460) at ../generator/GenItemFunc.cpp:864
> #9 0x00007fffec5255a2 in ExpGenerator::generateExpr (this=0x7fffd09e2d08, 
>  val_id=..., node_type=ex_expr::exp_SCAN_PRED, expr=0x7ffffffe98b8)
>  at ../generator/GenExpGenerator.cpp:2870
> ---Type <return> to continue, or q <return> to quit--- 
> #10 0x00007fffec5ff210 in HashJoin::codeGen (this=0x7fffd09d7590, generator=
>  0x7ffffffeb460) at ../generator/GenRelJoin.cpp:1185
> #11 0x00007fffec60f66e in RelRoot::codeGen (this=0x7fffd09d57c0, generator=
>  0x7ffffffeb460) at ../generator/GenRelMisc.cpp:1253
> #12 0x00007fffec501535 in Generator::genCode (this=0x7ffffffeb460, source=
>  0x7fffd3036ba8 "select t1.val from mytable t1, mytable t2 where UCASE(t1.c1) 
> = UCASE(t2.c1);", expr_node=0x7fffd09d57c0) at ../generator/Generator.cpp:557
> #13 0x00007fffeee01eae in CmpMain::compile (this=0x7ffffffeed60, input_str=
>  0x7fffd3036ba8 "select t1.val from mytable t1, mytable t2 where UCASE(t1.c1) 
> = UCASE(t2.c1);", charset=15, queryExpr=@0x7ffffffeec58, gen_code=
>  0x7fffd2ff69a8, gen_code_len=0x7fffd2ff69a0, heap=0x7fffd30391d8, phase=
>  CmpMain::END, fragmentDir=0x7ffffffeeeb8, op=3004, useQueryCache=
>  CmpMain::NORMAL, cacheable=0x7ffffffeec44, begTime=0x7ffffffeec60, 
>  shouldLog=0) at ../sqlcomp/CmpMain.cpp:2339
> #14 0x00007fffeedff94d in CmpMain::sqlcomp (this=0x7ffffffeed60, input_str=
>  0x7fffd3036ba8 "select t1.val from mytable t1, mytable t2 where UCASE(t1.c1) 
> = UCASE(t2.c1);", charset=15, queryExpr=@0x7ffffffeec58, gen_code=
>  0x7fffd2ff69a8, gen_code_len=0x7fffd2ff69a0, heap=0x7fffd30391d8, phase=
>  CmpMain::END, fragmentDir=0x7ffffffeeeb8, op=3004, useQueryCache=
>  CmpMain::NORMAL, cacheable=0x7ffffffeec44, begTime=0x7ffffffeec60, 
>  shouldLog=0) at ../sqlcomp/CmpMain.cpp:1653
> #15 0x00007fffeedfd23d in CmpMain::sqlcomp (this=0x7ffffffeed60, input=..., 
>  gen_code=0x7fffd2ff69a8, gen_code_len=0x7fffd2ff69a0, heap=0x7fffd30391d8, 
> ---Type <return> to continue, or q <return> to quit---q
> pQuit
> (gdb)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to