Skip to content

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

Description

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.

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions