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

Add support to resolve values of jsonb_object (and similar) functions #328

Open
cbruno10 opened this issue Jul 12, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@cbruno10
Copy link

For the aws_pricing_product table, sometimes we want to get prices for specific resources based on ID, name, etc., so we try to run a query like:

with volume_list as (
  select
    region,
    volume_type
  from
    aws_ebs_volume
)
select
  p.price_per_unit,
  p.filters
from
  volume_list as v
  left join aws_pricing_product as p on
    p.service_code = 'AmazonEC2'
    and p.filters =  jsonb_object(ARRAY['regionCode', v.region]::TEXT[])::text ::jsonb 
    and p.attributes ->> 'volumeApiName' = v.volume_type

The query runs and doesn't seem to ever finish.

The query plan looks a bit strange:

> explain with volume_list as (
  select
    region,
    volume_type
  from
    aws_ebs_volume
)
select
  p.price_per_unit,
  p.filters
from
  volume_list as v
  left join aws_pricing_product as p on
    p.service_code = 'AmazonEC2'
    and p.filters =  jsonb_object(ARRAY['regionCode', v.region]::TEXT[])::text ::jsonb 
    and p.attributes ->> 'volumeApiName' = v.volume_type
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| QUERY PLAN                                                                                                                                                            |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Nested Loop Left Join  (cost=0.00..20000400010000.00 rows=25000000 width=64)                                                                                          |
|   ->  Foreign Scan on aws_ebs_volume  (cost=0.00..20000000000000.00 rows=1000000 width=200)                                                                           |
|   ->  Foreign Scan on aws_pricing_product p  (cost=0.00..400.00 rows=1 width=400)                                                                                     |
|         Filter: ((service_code = 'AmazonEC2'::text) AND (service_code = 'AmazonEC2'::text) AND ((attributes ->> 'volumeApiName'::text) = aws_ebs_volume.volume_type)) |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant