Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query may return NULL columns if used in UNION ALL #95

Closed
mtuncer opened this issue May 9, 2016 · 1 comment
Closed

Query may return NULL columns if used in UNION ALL #95

mtuncer opened this issue May 9, 2016 · 1 comment

Comments

@mtuncer
Copy link
Member

mtuncer commented May 9, 2016

This issue is reported in cstore_fdw forum at https://groups.google.com/forum/#!topic/cstore-users/oqsWZHtlL74

Query 1:

(SELECT A*1 , B FROM TEST_UNION_1 LIMIT 10) UNION ALL (SELECT A*1 , B FROM TEST_UNION_2 LIMIT 10);

Query 2:

(SELECT A*1 , B FROM TEST_UNION_1 ) UNION ALL (SELECT A*1 , B FROM TEST_UNION_2 );

Query 1 works fine but Query 2 returns NULL columns . This is because in "ColumnList" function has the following code snippet

if (neededColumn->varattno == columnIndex)
{   
    column = neededColumn;
    break;
}

Query 1 --- varattno is 1,2 for a,b
Query 2 --- varattno is 141,2 for a,b

So CStore doesn't consider Column "a" and hence the NULL values.

@sriharsha9992
Copy link

Hi ,

I have already fixed the issue . When the plan has APPEND state , PG includes Exprs in the targetColumnList. So , the 141 was actually a OPEXPR (int4mul) . To fix this , all we have to do is ,

REPLACE
List *targetColumnList =baserel->reltargetlist;

WITH
List *targetColumnList = pull_var_clause(baserel->reltargetlist, PVC_RECURSE_AGGREGATES, PVC_RECURSE_PLACEHOLDERS);

Regards,
Harsha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants