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

sql: double check star expansion inside ORDER BY and GROUP BY for UDFs #97520

Closed
knz opened this issue Feb 22, 2023 · 2 comments
Closed

sql: double check star expansion inside ORDER BY and GROUP BY for UDFs #97520

knz opened this issue Feb 22, 2023 · 2 comments
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@knz
Copy link
Contributor

knz commented Feb 22, 2023

Followup to #95710
Foudn via #97515
Epic: CRDB-19496

If there is a star expansion insider ORDER BY or GROUP BY, we don't expand the list of columns in the UDF descriptor.

(This is also relevant for view descriptors after #97515 merges)

cc @DrewKimball @mgartner @rharding6373

Jira issue: CRDB-24735

@knz knz added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-sql-optimizer SQL logical planning and optimizations. T-sql-queries SQL Queries Team labels Feb 22, 2023
@rharding6373
Copy link
Collaborator

rharding6373 commented Feb 24, 2023

Doesn't look like postgres expands GROUP BY or ORDER BY:

rharding=# create table t (a int, b int);
CREATE TABLE
rharding=# create function f() returns setof record language sql begin atomic; select count(*) from t group by t.*; end;
CREATE FUNCTION
rharding=# \df+
                                                                                  List of functions
Source code        | Description 
---------------------------+-------------
  SELECT count(*) AS count+| 
    FROM t               +| 
    GROUP BY t.*;         +| 
 END  
rharding=# drop function f;
DROP FUNCTION
rharding=# create function f() returns setof record language sql begin atomic; select * from t order by t.*; end;
CREATE FUNCTION
rharding=# \df+
                                                                              List of functions
Source code    | Description 
------------------+-------------
SELECT t.a,    +| 
    t.b        +| 
    FROM t      +| 
   ORDER BY t.*;+| 
 END           

DISTINCT does do an expansion. We should support this case:

rharding=# create function f() returns setof record language sql begin atomic; select distinct * from t; end;
CREATE FUNCTION
rharding=# \df+
                                                                                List of functions
      Source code      | Description 
-----------------------+-------------
  SELECT DISTINCT t.a,+| 
      t.b,            +| 
      t.c             +| 
    FROM t;          +| 
 END    

@rharding6373
Copy link
Collaborator

Good news, we already do this for DISTINCT. I'm going to close this issue since we're currently compatible with postgres behavior.

[email protected]:26257/defaultdb> create function f() returns setof record language sql as $$ select    
                             -> distinct * from t; $$ ;                                                                     
CREATE FUNCTION
[email protected]:26257/defaultdb> show create function f;                                               
  function_name |                   create_statement
----------------+--------------------------------------------------------
  f             | CREATE FUNCTION public.f()
                |     RETURNS SETOF RECORD
                |     VOLATILE
                |     NOT LEAKPROOF
                |     CALLED ON NULL INPUT
                |     LANGUAGE SQL
                |     AS $$
                |     SELECT DISTINCT t.a, t.b FROM defaultdb.public.t;
                | $$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Archived in project
Development

No branches or pull requests

2 participants