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

Unexpected (wrong?) fetch and load INTO variable logic #7906

Open
EPluribusUnum opened this issue Dec 5, 2023 · 7 comments
Open

Unexpected (wrong?) fetch and load INTO variable logic #7906

EPluribusUnum opened this issue Dec 5, 2023 · 7 comments

Comments

@EPluribusUnum
Copy link

Hi *!

Looks like the full row evaluation/fetch not happens before loading values INTO variables, but the fetch+load happens for every column one after another.
I'd except the full row fetch happen before the variable loading. SQL standard has a rule to this behaviour?
3.0, 4.0 5.0 behaves the same.

This returns X, X, but I expect X, A.

EXECUTE BLOCK
RETURNS (
	c1 VARCHAR(1),
	c2 VARCHAR(1))
AS
BEGIN
  c1 = 'A';

  SELECT IIF(:c1 = 'A', 'X', 'Y'), :c1
  FROM rdb$database
  INTO :c1, :c2;

  SUSPEND;
END

Thank you!

@asfernandes
Copy link
Member

I'd say you are in an undefined behavior zone, and anything different than that would be slower.

@mrotteveel
Copy link
Member

I'm not sure what, if anything, ISO/IEC 9075-4 (PSM) has to say about this, but as Adriano says, it is likely undefined behaviour.

@EPluribusUnum
Copy link
Author

Alternative perspective. This returns X, A as expected and I just switched the column order. From set theory POW I think this is equivalent, columns order switch should not affect the result.

EXECUTE BLOCK
RETURNS (
	c1 VARCHAR(1),
	c2 VARCHAR(1))
AS
BEGIN
  c1 = 'A';

  SELECT :c1, IIF(:c1 = 'A', 'X', 'Y')
  FROM rdb$database
  INTO :c2, :c1;

  SUSPEND;
END

@AlexPeshkoff
Copy link
Member

AlexPeshkoff commented Dec 5, 2023 via email

@aafemt
Copy link
Contributor

aafemt commented Dec 5, 2023

Nevertheless update behavior is defined: fields in every calculations are seen in state they were before actual modifications. Shouldn't select follow the same conventions calculating whole returned record on fetch instead of leaving it on assignments?

@dyemanov
Copy link
Member

dyemanov commented Dec 5, 2023

While we fixed the fields references in updates in the past, I believe they still suffer from the same issue when variables are used. I suppose variables are outside any rules declared in the SQL specification.

@mrotteveel
Copy link
Member

Rules for variables are likely defined in Part 4 (PSM).

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

No branches or pull requests

6 participants