src-d / gitbase

SQL interface to git repositories, written in Go. https://docs.sourced.tech/gitbase
Apache License 2.0
2.07k stars 123 forks source link

HAVING + ORDER BY doesn't work #937

Closed se7entyse7en closed 5 years ago

se7entyse7en commented 5 years ago

Version used: v0.24.0-beta1.

Running a query that has a HAVING followed by an ORDER BY doesn't work. Here's the query that I tried:

SELECT table_schema  AS TABLE_CAT, 
       NULL          AS TABLE_SCHEM, 
       table_name, 
       CASE 
         WHEN table_type = 'BASE TABLE' THEN 
           CASE 
             WHEN table_schema = 'mysql' 
                   OR table_schema = 'performance_schema' THEN 'SYSTEM TABLE' 
             ELSE 'TABLE' 
           end 
         WHEN table_type = 'TEMPORARY' THEN 'LOCAL_TEMPORARY' 
         ELSE table_type 
       end           AS TABLE_TYPE, 
       table_comment AS REMARKS, 
       NULL          AS TYPE_CAT, 
       NULL          AS TYPE_SCHEM, 
       NULL          AS TYPE_NAME, 
       NULL          AS SELF_REFERENCING_COL_NAME, 
       NULL          AS REF_GENERATION 
FROM   information_schema.tables 
WHERE  table_schema = 'gitbase' 
       AND table_name = 'repositories' 
HAVING table_type IN ( 'TABLE', 'VIEW', NULL, NULL, NULL ) 
ORDER  BY table_type, 
          table_schema, 
          table_name; 

This raises: ERROR 1105 (HY000): unknown error: unable to push plan.Sort node below *plan.Having.

The same query without the HAVING clause or without the ORDER BY clause works.

erizocosmico commented 5 years ago

Will be fixed when https://github.com/src-d/go-mysql-server/pull/793 is merged