Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove multiplicity from QueryUnit.sql #7985

Merged
merged 3 commits into from
Nov 12, 2024
Merged

Remove multiplicity from QueryUnit.sql #7985

merged 3 commits into from
Nov 12, 2024

Conversation

elprans
Copy link
Member

@elprans elprans commented Nov 12, 2024

Currently, QueryUnit.sql is a tuple representing, possibly, multiple
SQL statements corresponding to the original EdgeQL statement. This
introduces significant complexity to consumers of QueryUnit, which are
mostly unprepared to handle more than one SQL statement anyway.

Originally the SQL tuple was used to represent multiple EdgeQL statements,
a task which is now handled by the QueryUnitGroup stuff. Another use
case are the non-transactional commands (CREATE BRANCH and friends).
Finally, since this facility was available, more uses of it were added
without actually needing be executed as multiple SQL statements
with no other recourse: those are mostly maintenance commands and the
DDL type_id readback.

I think the above uses are no longer a sufficient reason to keep the
tuple complexity and so I'm ripping it out here, making QueryUnit.sql
a bytes property with the invariant of always containing exactly one
SQL statement and thus not needing any special handling. The users are
fixed up as follows:

  • Non-transactional branch units encode the extra SQL needed to
    represent them in the new QueryUnit.db_op_trailer property which is
    a tuple of SQL. Branch commands have special handling for them
    already, so this is not a nuisance.

  • The newly-added type id mappings produced by DDL commands are now
    communicated via the new "indirect return" mechanism, whereby a DDL
    PLBlock can communicate a return value via a specially-formatted
    NoticeResponse message.

  • All other unwitting users of multi-statement QueryUnit are converted
    to use a single statement instead (primarily by converting them to use a
    DO block).

Currently, `QueryUnit.sql` is a tuple representing, possibly, multiple
SQL statements corresponding to the original EdgeQL statement.  This
introduces significant complexity to consumers of `QueryUnit`, which are
mostly unprepared to handle more than one SQL statement anyway.

Originally the SQL tuple was used to represent multiple EdgeQL statements,
a task which is now handled by the `QueryUnitGroup` stuff.  Another use
case are the non-transactional commands (`CREATE BRANCH` and friends).
Finally, since this facility was available, more uses of it were added
without actually _needing_ be executed as multiple SQL statements
with no other recourse: those are mostly maintenance commands and the
DDL type_id readback.

I think the above uses are no longer a sufficient reason to keep the
tuple complexity and so I'm ripping it out here, making `QueryUnit.sql`
a `bytes` property with the invariant of _always_ containing exactly one
SQL statement and thus not needing any special handling.  The users are
fixed up as follows:

- Non-transactional branch units encode the extra SQL needed to
  represent them in the new `QueryUnit.db_op_trailer` property which is
  a tuple of SQL.  Branch commands have special handling for them
  already, so this is not a nuisance.

- The newly-added type id mappings produced by DDL commands are now
  communicated via the new "indirect return" mechanism, whereby a DDL
  PLBlock can communicate a return value via a specially-formatted
  `NoticeResponse` message.

- All other unwitting users of multi-statement `QueryUnit` are converted
  to use a single statement instead (primarily by converting them to use a
  `DO` block).
Copy link
Member

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

It's a little unclear to me that this is actually simpler, since pulling results out via NOTICE feels wildly janky. I guess it won't feel as janky the next time we have to do it, for better or worse.

Comment on lines +740 to +745
"statements": [{"text": stmt} for stmt in self.statements],
"confidence": self.confidence,
"prompt": self.prompt,
"prompt_id": self.prompt_id,
"data_safe": self.data_safe,
"required_user_input": list(self.required_user_input),
Copy link
Member

Choose a reason for hiding this comment

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

It's probably not worth undoing but all these automated changes make this diff pointlessly noisy

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure how this happened, I don't have format-on-save enabled.

Copy link
Member

Choose a reason for hiding this comment

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

You clearly have something enabled, plenty of changes here just change ' to "

Copy link
Member Author

Choose a reason for hiding this comment

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

Must have pressed a "format file" shortcut or something. It's just this file.

@elprans
Copy link
Member Author

elprans commented Nov 12, 2024

It's a little unclear to me that this is actually simpler, since pulling results out via NOTICE feels wildly janky

Yeah, it does seem like it at first, but the mechanism is reliable. There are more cleanups to be realized from the single-statement invariant of QueryUnit that aren't here.

@elprans elprans merged commit 1c16dbd into master Nov 12, 2024
23 checks passed
@elprans elprans deleted the query-unit-cleanup branch November 12, 2024 21:19
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