citusdata / citusdata/citus

Long Query error out with out of memory

Open
#4,316 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

While running a lengthy query, I got the following error

`could not Retrieve the result : ERROR: out of memory
DETAIL: Failed on request of size 1048576 in memory context "ErrorContext".`

Following is the query I ran

`select
count( case when date(timezone)=current_date then anonymous_id end) as Today,
count( case when date(timezone)=current_date-1 then anonymous_id end) as Yesterday,
count( case when date(timezone)=current_date-2 then anonymous_id end) as today2,
count( case when date(timezone)=current_date-4 then anonymous_id end) as today3
from
(select x1.anonymous_id,x2.user_id,utm_source,x1.timezone,x1.utm_source
from
(select anonymous_id,user_id,utm_source,timestamp at time zone 'utc' at time zone 'asia/kolkata' as timezone
from tbl1
where date(timestamp at time zone 'utc' at time zone 'asia/kolkata')>=current_date-4
union all
select anonymous_id,user_id,utm_source,timestamp at time zone 'utc' at time zone 'asia/kolkata'
from tbl2
where date(timestamp at time zone 'utc' at time zone 'asia/kolkata')>=current_date-4
union all
select anonymous_id,user_id,utm_source,timestamp at time zone 'utc' at time zone 'asia/kolkata'
from tbl3
where date(timestamp at time zone 'utc' at time zone 'asia/kolkata')>=current_date-4)x1
left join
(select *
from
(
select distinct user_id,anonymous_id
from tbl1
where user_id is not null
union
select distinct user_id,anonymous_id
from tbl2
where user_id is not null
union
select distinct user_id,anonymous_id
from tbl3
where user_id is not null) xyz
where anonymous_id not in(
select anonymous_id
from
(
select distinct user_id,anonymous_id
from tbl1
where user_id is not null
union
select distinct user_id,anonymous_id
from tbl2
where user_id is not null
union
select distinct user_id,anonymous_id
from tbl3
where user_id is not null
) abc
group by 1
having count(*)>1 offset 0
)
)x2
on x1.anonymous_id=x2.anonymous_id)t
where ((user_id is not null) and (user_id in ('1','2','3', <170210 string elements>)
)))`

I fixed this up by storing the user_id values (used in `user_id in ('",c,"'))`) into a table and replacing condition with `user_id in (Select user_id from user_id_table)`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.