Query Results Re-Use

When you re-run a query in Athena, you can optionally choose to reuse the last stored query result. This option can increase performance and reduce costs in terms of the number of bytes scanned.

Reusing query results is useful if you know that the results will not change within a given time frame. You can specify a maximum age for reusing query results. Athena will use the stored result as long as it is not older than the specified age.


Verify the Reuse Query Results Feature

  1. Open the Athena console by typing Athena in the search bar at the top of the screen.
  2. Select Athena from the search results.
  3. Check if the Reuse query results option is already enabled:
    • Click the Reuse query results toggle button.
    • If it is enabled, skip to the Testing the reuse query results feature section.
    • Otherwise, complete the following steps to enable the feature.
      Connect

Enable Query Results Reuse

  1. Select Workgroups under the Administration menu on the left sidebar.
  2. Click on the primary workgroup from the list of workgroups.
    Connect
  3. Click the Edit button in the top-right corner to edit the workgroup settings.
    Connect
  4. In the Upgrade Query Engine section:
    • Click the Manual radio button.
    • Select Athena engine version 3 from the Query engine version dropdown.
      Connect
  5. Click the Save Changes button in the bottom-right corner.
    Connect

Testing the Reuse Query Results Feature

Steps:

  1. Navigate back to the Query editor.

  2. Click the + icon to add a new tab. Connect

  3. Copy and paste the query below into the query editor:

    SELECT * FROM default.customers_csv LIMIT 10;
    
  4. Click the Reuse query results toggle to the off position.

  5. Click the Run button.
    Connect

  6. Note down the Run time and Data scanned values.
    Connect

  7. Click the Reuse query results toggle to turn it on. Connect

  8. Click the edit icon (pencil) under Reuse query results.

  9. Set the reuse time to 10 minutes, then click Confirm.
    Connect

  10. Re-run the query by clicking Run again.

  11. Compare the Run time and Data scanned values with the original run.

  12. Go to the Recent Queries tab in the query editor.

  13. Check the Cache column to see the Result reuse value added to the execution.

Connect

Note: You may need to scroll across to find the Cache column.

  1. Re-run the query with different reuse time’s and verify the behaviour. For example change the reuse time from 30 minutes to 1 minute using the

You have now successfully explored the query results reuse feature in Amazon Athena.