[MDEV-20924] Unify grammar rules: field_type_string and sp_param_field_type_string Created: 2019-10-30  Updated: 2020-01-23  Resolved: 2019-10-30

Status: Closed
Project: MariaDB Server
Component/s: Parser
Fix Version/s: 10.5.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-12518 Unify sql_yacc.yy and sql_yacc_ora.yy Closed

 Description   

sql_yacc_ora.yy has two separate set of rules to parse data types:

  • field_type, field_type_string - for table fields and SP local variables
  • sp_param_field_type, sp_param_field_type_string - SP parameters and SF return values

Let's remove the second set of rules and use field_type/field_type_string for in all cases.
Advantages:

  • Unification of sql_yacc.yy and sql_yacc_ora.yy
  • Move more code from the *.yy files to Type_handler, so data type plugins have more flexibility.

In order to move the code from *.yy to Type_handler, let's introduce this enum:

enum column_definition_type_t
{
  COLUMN_DEFINITION_TABLE_FIELD,
  COLUMN_DEFINITION_ROUTINE_PARAM,
  COLUMN_DEFINITION_ROUTINE_LOCAL,
  COLUMN_DEFINITION_FUNCTION_RETURN
};

and this virtual method:

virtual bool Column_definition_set_attributes(THD *thd,
                                              Column_definition *def,
                                              const Lex_field_type_st &attr,
                                              CHARSET_INFO *cs,
                                              column_definition_type_t type)
                                              const;

So, for example, Type_handler_varchar::Column_definition_set_attributes() will do the following:

  • If the length is specified explictly, set def->length accordingly.
  • If the length is not specified explicitly, then
    • In case of a table field type and a local variable type it will return a syntax error
    • In case of an SP parameter type and an SF return type and sql_mode=DEFAULT, it will return a syntax error.
    • In case of an SP parameter type and sql_mode=ORACLE, it will set def in the way that later the formal parameter length is adjusted to the actual parameter length.
    • In case of an SF return type and sql_mode=ORACLE, it will set def->length to the default value (4000).

Generated at Thu Feb 08 09:03:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.