Optimize performance

Can PostgreSQL return the same answer faster?

Once a view, function or procedure passes verification, compare its runtime with the source. Optimize tests a PostgreSQL rewrite or an index and shows whether the change made the same work measurably faster.

Optimization criteria

What does a change have to prove?

  • Check
    Correctness
    Condition for acceptance
    The object passes on the proposed PostgreSQL code.
  • Check
    Dependencies
    Condition for acceptance
    Previously passing objects affected by the change still pass.
  • Check
    Index creation
    Condition for acceptance
    PostgreSQL successfully creates any proposed index.
  • Check
    Median latency
    Condition for acceptance
    The drop in median exceeds the baseline gap between its median and 95th percentile.
  • Check
    95th percentile
    Condition for acceptance
    The candidate’s 95th percentile is at or below the baseline’s.

The timing checks compare the candidate with the current PostgreSQL implementation using the same invocation.

Which workload do the timings describe?

A view is timed through the fetch of its last row. For a routine, Logic Proof uses the arguments from the first test whose source call completed without raising an error. If that call looks up a single employee, the timings describe that lookup on the test data.

See where the timing agents run

Find the calls worth tuning

A verification run automatically times eligible objects on the data it tested. After warm-up, the agents time repeated calls inside each database’s network. By default, Logic Proof flags a target as slower when its median exceeds the source median by more than 20% and is also above the source’s 95th percentile.

Read the plan and try a specific change

Optimize measures the current target again. The model uses the SQL, its dependencies, the timings and available execution plans to propose a rewrite, an index, or both. For a view joining employees to departments, it can propose an index on the employee table’s department ID. A unique index there would prevent two employees from sharing a department, so Logic Proof rejects it.

Check behavior before measuring the candidate

The candidate must pass the object’s tests. If the rewrite or the indexed table affects another object that passed, that object must pass again. The engine also checks that PostgreSQL created the proposed index. Only candidates that meet those conditions go on to the timing comparison.

Compare the gain with the target’s own variation

To qualify, the candidate’s median must improve by more than the gap between the current target’s median and its 95th percentile. The candidate’s own 95th percentile must hold steady or improve. Read-only mode saves a qualifying revision for review. Assisted mode makes it the project target.

How to interpret an optimization result

What is included in a measured call?

An agent opens a connection, warms up the invocation, then times execution through the last row fetched. Connection setup is outside the timed interval. Each side measures calls in its own network, and each agent runs its batch sequentially so adjacent benchmark calls on that database do not compete with each other.

For a review, read the input arguments and the individual timings alongside the median and 95th percentile. A lookup of one customer on synthetic data describes that workload. Production concurrency and a month-end batch are separate workloads.

Why might a passing procedure have no automatic timing?

A routine can pass because it raised the same expected error on both systems. If every tested input raises an error on the source, there is no successful invocation to benchmark. Other routines commit internally, schedule jobs, or write outside their transaction.

Logic Proof screens for those side effects before repeating a call automatically. Inspect the reason on the object before choosing whether it is appropriate to measure on demand in your test environment.

What kinds of changes can the optimizer try?

It can rewrite the object, add a named index to a table it reads, or combine both. An index must be created successfully in staging. Unique indexes are excluded because they would change which writes the table accepts.

An index changes the test scope as well as the plan. Previously passing objects affected by the indexed table must still pass before the candidate is timed. If no candidate clears both the correctness and timing checks, the current PostgreSQL implementation stays in place.

What does your team need to verify?

Tell us which database you’re moving, how far the PostgreSQL code has come, and which behaviors matter most at cutover.

Cookie settings

Choose what Spectral Core can use on this browser. You can change your choices at any time.

Essential storageRemembers your privacy choices.
Always on