Skip to content

Optimize SQL queries with (materialized?) view #1589

Closed

Description

@vito

Feature Request

What challenge are you facing?

Polling is a common part of both Concourse's UI and internal things like garbage collection. In a stable state, a lot of things that we're polling aren't changing, but the query to poll for them is expensive (ish).

One example is the pipeline view: every 5 seconds, we get the latest completed build and nextmost started/pending build for each job. This query is nontrivial and has a lot of impact on the user, as it determines the speed of the pipeline UI. As part of the dashboard work, a third query was added, for the current "transitional" build (the first build that got the job in its current state), which is even more expensive to compute.

Similarly, garbage collection entails finding the latest completed build of each job, to know which builds can be marked non-interceptible.

One problem is expressiveness: we repeat the same logic in a few different contexts, and it's not immediately clear, as it's just SQL embedded in SQL.

Another problem is efficiency: it's pretty silly to be causing so much load and being so slow when really the data only changes when e.g. a build runs.

A Modest Proposal

To solve the first problem of expressiveness, we can start using VIEWs. This allows us to at least give the query a name, simplify each query, and make it easier to see patterns among our queries.

To solve the second problem, we can transition these to MATERIALIZED VIEW, and do a REFRESH MATERIALIZED VIEW CONCURRENTLY when the data set changes. This will make the reads much quicker.

Activity

  1. changed the title [-]optimize sql queries with view (materialized?)[/-] [+]Optimize SQL queries with (materialized?) view[/+] on Sep 13, 2017
  2. vito commented on Oct 26, 2017

    @vito
    ContributorAuthor

    Done! We observed significant performance improvement on Wings.

  3. added this to the v3.6.0 milestone on Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions