You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I’m not exactly sure what the issue is, but there is a problem where the query results come out strangely when using a CTE without materialized hint.
For example, when explain a query like the following: (The query is quite long, and you don’t need to look at it. Ultimately, what I want to show is the difference in explain results depending on whether the materialized hint is used or not.)
explain with parsed_data as (
selectd.namespace,
d.name,
d.replicas,
pdb.min_available,
pdb.max_unavailable,
case
when pdb.min_availableis not null then
regexp_replace(pdb.min_available::text, '.*IntVal:([0-9]*).*', '\1')::int
else null
end as min_available_int_val,
case
when pdb.min_availableis not nulland
regexp_replace(pdb.min_available::text, '.*StrVal:([0-9.]*)%?.*', '\1') !='' then
round(regexp_replace(pdb.min_available::text, '.*StrVal:([0-9.]*)%?.*', '\1')::numeric/100, 2)
else null
end as min_available_str_val,
case
when pdb.max_unavailableis not null then
regexp_replace(pdb.max_unavailable::text, '.*IntVal:([0-9]*).*', '\1')::int
else null
end as max_unavailable_int_val,
case
when pdb.max_unavailableis not nulland
regexp_replace(pdb.max_unavailable::text, '.*StrVal:([0-9.]*)%?.*', '\1') !='' then
round(regexp_replace(pdb.max_unavailable::text, '.*StrVal:([0-9.]*)%?.*', '\1')::numeric/100, 2)
else null
end as max_unavailable_str_val
fromk8s_main.kubernetes_pod_disruption_budget pdb
inner joink8s_main.kubernetes_deployment d ond.selector=pdb.selectorandd.namespace=pdb.namespace
)
select
namespace,
name,
min_available,
max_unavailable,
replicas,
min_available_int_val
from
parsed_data
where
min_available_int_val >= replicas
order by
namespace,
name;
As you can see, the explain plan does not include any condition related to min_available_int_val >= replicas. So, when executing the query, this where clause is not applied at all, resulting in all rows being returned.
If I add the materialized hint, everything works correctly
explain with parsed_data as materialized (
selectd.namespace,
d.name,
d.replicas,
pdb.min_available,
pdb.max_unavailable,
case
when pdb.min_availableis not null then
regexp_replace(pdb.min_available::text, '.*IntVal:([0-9]*).*', '\1')::int
else null
end as min_available_int_val,
case
when pdb.min_availableis not nulland
regexp_replace(pdb.min_available::text, '.*StrVal:([0-9.]*)%?.*', '\1') !='' then
round(regexp_replace(pdb.min_available::text, '.*StrVal:([0-9.]*)%?.*', '\1')::numeric/100, 2)
else null
end as min_available_str_val,
case
when pdb.max_unavailableis not null then
regexp_replace(pdb.max_unavailable::text, '.*IntVal:([0-9]*).*', '\1')::int
else null
end as max_unavailable_int_val,
case
when pdb.max_unavailableis not nulland
regexp_replace(pdb.max_unavailable::text, '.*StrVal:([0-9.]*)%?.*', '\1') !='' then
round(regexp_replace(pdb.max_unavailable::text, '.*StrVal:([0-9.]*)%?.*', '\1')::numeric/100, 2)
else null
end as max_unavailable_str_val
fromk8s_main.kubernetes_pod_disruption_budget pdb
inner joink8s_main.kubernetes_deployment d ond.selector=pdb.selectorandd.namespace=pdb.namespace
)
select
namespace,
name,
min_available,
max_unavailable,
replicas,
min_available_int_val
from
parsed_data
where
min_available_int_val >= replicas
order by
namespace,
name;
The only difference is the materialized hint at the top, but when checking the plan, we can see that Filter: (min_available_int_val >= replicas) is properly included, and the query executes as intended.
In fact, besides this example, I’ve encountered similar cases a few times before. Each time, I just added the materialized hint to resolve the issue.
If this is a known issue and adding the materialized hint is the appropriate workaround, it would be helpful to explicitly mention it in the documentation—so others don’t have to struggle with the same issue like I did.
On the other hand, if this behavior is unintended and a clear bug, then it should be investigated and fixed at the root cause.
Steampipe version (steampipe -v)
v1.0.3
To reproduce
I haven’t been able to find a minimal, reproducible example. If you have the k8s plugin, please refer to [Describe the bug].
Expected behavior
"Ensuring that the where clause is not omitted even without the materialized hint” or “Documenting this issue with a workaround as guidance.”
Additional context
N/A
The text was updated successfully, but these errors were encountered:
dongho-jung
changed the title
Weird query behavior when using CTE without materialized hint
[WIP] Weird query behavior when using CTE without materialized hint
Mar 12, 2025
dongho-jung
changed the title
[WIP] Weird query behavior when using CTE without materialized hint
Weird query behavior when using CTE without materialized hint
Mar 12, 2025
Thank you, @dongho-jung, for taking the time to raise this detailed issue. The issues you mentioned are similar, but I'm unsure if they are the same. I will look into this and update this thread.
Meanwhile if you can find a minimal reproducible example, let us know.
Describe the bug
I’m not exactly sure what the issue is, but there is a problem where the query results come out strangely when using a CTE without materialized hint.
For example, when
explain
a query like the following: (The query is quite long, and you don’t need to look at it. Ultimately, what I want to show is the difference inexplain
results depending on whether thematerialized
hint is used or not.)explain
results are as follows:As you can see, the
explain
plan does not include any condition related tomin_available_int_val >= replicas
. So, when executing the query, thiswhere
clause is not applied at all, resulting in all rows being returned.If I add the
materialized
hint, everything works correctly->
The only difference is the
materialized
hint at the top, but when checking the plan, we can see thatFilter: (min_available_int_val >= replicas)
is properly included, and the query executes as intended.In fact, besides this example, I’ve encountered similar cases a few times before. Each time, I just added the
materialized
hint to resolve the issue.I looked it up and found a few similar cases:
aws_ecr_image
steampipe-postgres-fdw#435If this is a known issue and adding the
materialized
hint is the appropriate workaround, it would be helpful to explicitly mention it in the documentation—so others don’t have to struggle with the same issue like I did.On the other hand, if this behavior is unintended and a clear bug, then it should be investigated and fixed at the root cause.
Steampipe version (
steampipe -v
)v1.0.3
To reproduce
I haven’t been able to find a minimal, reproducible example. If you have the k8s plugin, please refer to [Describe the bug].
Expected behavior
"Ensuring that the
where
clause is not omitted even without thematerialized
hint” or “Documenting this issue with a workaround as guidance.”Additional context
N/A
The text was updated successfully, but these errors were encountered: