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

When executing a query with matrix items, if non key-column quals are used which filter the matrix item list, they must be included in the cache key #402

Closed
kaidaguerre opened this issue Sep 2, 2022 · 0 comments · Fixed by #403

Comments

@kaidaguerre
Copy link
Contributor

kaidaguerre commented Sep 2, 2022

interesting edge case bug in the way matrix (multi-region) queries work.

When a query is executed with matrix is defined (e.g. a list of regions), there is optimisation code which removes items from the list if they are excluded by the quals (even if no key column is defined).

This is the reason
select * from aws_ec2_transit_gateway
returns an error but
select * from aws_ec2_transit_gateway where region = 'us-east-1'
does not. In this case only 'us-east-1 is executed, even though the plugin itself does not do explicit filtering using region

When caching however, only key column quals are used when building the cache key. So when running
select * from aws_ec2_transit_gateway where region = 'us-east-1'
the result gets cached without region being in the cache key. This means when we later run
select * from aws_ec2_transit_gateway where region = 'me-central-1'
we get a cache hit.

A worse symptom of this bug is if we first query a region with no result, then a region with results. In this case, the second query would incorrectly return no results:

> select * from aws_ec2_transit_gateway where region = 'us-east-1'
+--------------------+---------------------+-------+----------+-------------+---------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+------------------+-------------+----------+------+-------+------+-----------+--------+-----
| transit_gateway_id | transit_gateway_arn | state | owner_id | description | creation_time | amazon_side_asn | association_default_route_table_id | auto_accept_shared_attachments | default_route_table_association | default_route_table_propagation | dns_support | multicast_support | propagation_default_route_table_id | vpn_ecmp_support | cidr_blocks | tags_src | tags | title | akas | partition | region | acco
+--------------------+---------------------+-------+----------+-------------+---------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+------------------+-------------+----------+------+-------+------+-----------+--------+-----
+--------------------+---------------------+-------+----------+-------------+---------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+------------------+-------------+----------+------+-------+------+-----------+--------+-----

Time: 1.0s.
> select * from aws_ec2_transit_gateway where region = 'us-east-2'
+--------------------+---------------------+-------+----------+-------------+---------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+------------------+-------------+----------+------+-------+------+-----------+--------+-----
| transit_gateway_id | transit_gateway_arn | state | owner_id | description | creation_time | amazon_side_asn | association_default_route_table_id | auto_accept_shared_attachments | default_route_table_association | default_route_table_propagation | dns_support | multicast_support | propagation_default_route_table_id | vpn_ecmp_support | cidr_blocks | tags_src | tags | title | akas | partition | region | acco
+--------------------+---------------------+-------+----------+-------------+---------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+------------------+-------------+----------+------+-------+------+-----------+--------+-----
+--------------------+---------------------+-------+----------+-------------+---------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+------------------+-------------+----------+------+-------+------+-----------+--------+-----

in this case - us-east-2 does have results, as seen by clearing the cache:

> .cache clear
> select * from aws_ec2_transit_gateway where region = 'us-east-2'
+-----------------------+--------------------------------------------------------------------------+-----------+--------------+--------------------+---------------------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+---------
| transit_gateway_id    | transit_gateway_arn                                                      | state     | owner_id     | description        | creation_time             | amazon_side_asn | association_default_route_table_id | auto_accept_shared_attachments | default_route_table_association | default_route_table_propagation | dns_support | multicast_support | propagation_default_route_table_id | vpn_ecmp
+-----------------------+--------------------------------------------------------------------------+-----------+--------------+--------------------+---------------------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+---------
| tgw-0a966b15e2449f879 | arn:aws:ec2:us-east-2:786233995633:transit-gateway/tgw-0a966b15e2449f879 | available | 786233995633 | Turbot Transit VPC | 2020-04-23T17:02:12+01:00 | 64512           | tgw-rtb-05a28cad94595bbb3          | enable                         | enable                          | enable                          | enable      | disable           | tgw-rtb-05a28cad94595bbb3          | enable  
+-----------------------+--------------------------------------------------------------------------+-----------+--------------+--------------------+---------------------------+-----------------+------------------------------------+--------------------------------+---------------------------------+---------------------------------+-------------+-------------------+------------------------------------+---------

fix for this is that if any non keycolumn qual is used to filter the matrix items, it will be included in the cache key.

@kaidaguerre kaidaguerre transferred this issue from turbot/steampipe Sep 2, 2022
kaidaguerre added a commit that referenced this issue Sep 2, 2022
… used which filter the matrix item list, they must be included in the cache key. Closes #402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant