Skip to content

Auto-generated SQL instead of hand-written comments#10061

Open
smklein wants to merge 3 commits intomainfrom
expectorate-no-comment
Open

Auto-generated SQL instead of hand-written comments#10061
smklein wants to merge 3 commits intomainfrom
expectorate-no-comment

Conversation

@smklein
Copy link
Collaborator

@smklein smklein commented Mar 13, 2026

Inspired by #10050

This PR adds expectorate tests, and removes "hand-written SQL comments", because they can easily
get out-of-sync with reality.

Removed "giant SQL block comment" for:

  • network_interface.rs - DeleteQuery: Already has expectorate test
  • deployment.rs - insert_target_query: Already has expectorate test
  • datastore/ip_pool.rs - link_ip_pool_to_external_silo_query: Already has expectorate test
  • queries/ip_pool.rs - FilterOverlappingIpRanges - new expectorate test added
  • vpc_subnet.rs - InsertVpcSubnetQuery - new expectorate test added

Comment on lines -1611 to -1618
/// (SELECT
/// state
/// FROM
/// instance
/// WHERE
/// id = <instance_id> AND
/// time_deleted IS NULL
/// ),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, this comment was already out-of-sync with the real query.

In reality, this is:

  SELECT
      CASE WHEN active_propolis_id IS NULL THEN state ELSE $1 END
  FROM
      instance
  WHERE
      id = $2 AND time_deleted IS NULL

Which is a subtle-but-important difference, but the sorta thing you might care about if you're trying to see how the query works.

@david-crespo
Copy link
Contributor

Love this

@smklein smklein requested review from bnaecker and jgallagher March 13, 2026 19:48
/// kind = <kind> AND
/// time_deleted IS NULL
/// ) <= 1,
/// '<interface_id>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, another fun fact - this was also out of date, except that #10059 (comment) changes it to be not-wrong-anymore. 😅 (Irrelevant since it's going away.)

/// -- record, have overlapping IP blocks of either family.
/// overlap AS MATERIALIZED (
/// SELECT
/// -- NOTE: This cast always fails, we just use _how_ it fails to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this comment doesn't already exist elsewhere, might be worth moving it to a Rust comment where the SQL is being generated.

(Same issue on the other block comments that document inner parts of the CTEs.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9552e76

/// <new_target_time_made_target>
/// FROM new_target
/// ```
/// query we generate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about putting in the filename where you can find the snapshot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9552e76

@smklein
Copy link
Collaborator Author

smklein commented Mar 13, 2026

looks like the live some tests flaked for a reason unrelated to this PR; filed #10063

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants