Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-8356

Table functions: Make sure CREATE FUNCTION works for table-returning functions

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • N/A
    • OTHER
    • None

    Description

      This is a part of dj's GSoC project. The idea is to make sure the server is able to execute a statement that creates an SQL table function

      CREATE FUNCTION func_name (args)  RETURNS TABLE table_name (column type [, column type ...]) BEGIN  <function body here> END; 

      and save the function appropriately.

      Attachments

        Issue Links

          Activity

            dj diwas joshi added a comment -

            ok after MDEV-8342 and MDEV-8343. There are two main things here: type of sf and return type of sf. Right now the create function... is giving errors at

            store_failed= store_failed ||
            table->field[MYSQL_PROC_MYSQL_TYPE]->
            store((longlong)type, TRUE);

            in sf_create_routine(), which is right since we have been been using TYPE_ENUM_TABLE for m_type so far and mysql.proc takes enum('FUNCTION','PROCEDURE') for type so far. Now we have decided to store both functions as TYPE_ENUM_FUNCTION for now and functions can be differentiated using return types.

            The second thing is about return type of function. Right now sp_returns_type() method is being used to store the return type of functions. But in our case we have a list of create_fields: List<Create_field> m_cols_list keeping list of attribute names and their types for the table. The type of the field storing return type right now is longblob which as i read further on it is a binary large object that can hold a variable amount of data and are treated as binary strings (byte strings). We have decided to store all the attribute information in this field only, in a single string eg. TABLE <table_alias>(<col_definitions>).

            Also, another thing is to store the table alias m_table_alias, because queries inside the function will be using it. There is no field present specifically for this in mysql.proc. So we finally decided to store the table alias as part of return type string for now.

            dj diwas joshi added a comment - ok after MDEV-8342 and MDEV-8343 . There are two main things here: type of sf and return type of sf. Right now the create function... is giving errors at store_failed= store_failed || table->field [MYSQL_PROC_MYSQL_TYPE] -> store((longlong)type, TRUE); in sf_create_routine(), which is right since we have been been using TYPE_ENUM_TABLE for m_type so far and mysql.proc takes enum('FUNCTION','PROCEDURE') for type so far. Now we have decided to store both functions as TYPE_ENUM_FUNCTION for now and functions can be differentiated using return types. The second thing is about return type of function. Right now sp_returns_type() method is being used to store the return type of functions. But in our case we have a list of create_fields: List<Create_field> m_cols_list keeping list of attribute names and their types for the table. The type of the field storing return type right now is longblob which as i read further on it is a binary large object that can hold a variable amount of data and are treated as binary strings (byte strings). We have decided to store all the attribute information in this field only, in a single string eg. TABLE <table_alias>(<col_definitions>). Also, another thing is to store the table alias m_table_alias, because queries inside the function will be using it. There is no field present specifically for this in mysql.proc. So we finally decided to store the table alias as part of return type string for now.

            Diwas pushed the fix into his tree.

            psergei Sergei Petrunia added a comment - Diwas pushed the fix into his tree.

            People

              Unassigned Unassigned
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.