Skip to content
  • Gopal Shankar's avatar
    d8453a0d
    Bug#30766181 I_S.KEY_COLUMN_USAGE IS VERY SLOW · d8453a0d
    Gopal Shankar authored
    Bug#30216864 INFORMATION_SCHEMA.KEY_COLUMN_USAGE PERFORMANCE IS SLOW
    
    Problem:
    The system views INFORMATION_SCHEMA.KEY_COLUMN_USAGE and
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS uses UNION. This causes the
    conditions to be evaluated once per each SELECT statement which
    are part of UNION.  This causes dictionary metadata to be
    traversed multiple times. Mainly the metadata tables mysql.schema
    and mysql.tables would be traversed multiple times. And this
    intern causes the access checks for SQL objects to be done
    multiple times.
    
    Fix:
    Rewrite the system views for INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    and INFORMATION_SCHEMA.TABLE_CONSTRAINTS to move UNION into a
    LATERAL table. That way, it is be possible to merge the view and
    the conditions on schema name and table name is applied before
    the lateral table is executed, enabling indexes of the specified
    table to be accessed.
    
    There is following change in behavior with this patch. The column
    names of two INFORMATION_SCHEMA tables would be presented as
    capitalized column names and not the case provided by user in the
    query.
    
    E.g.,
      SELECT Table_Name, Constraint_name
        FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS (or KEY_COLUMN_USAGE) LIMIT 1;
      TABLE_NAME      CONSTRAINT_NAME
      ...
    
      Unlike, the behavior before patch is that we get user provided case,
    
      SELECT Table_Name, Constraint_name
        FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS (or KEY_COLUMN_USAGE) LIMIT 1;
      Table_Name      Constraint_name
      ...
    
    The new behavior is same as seen in other INFORMATION_SCHEMA
    tables based on system view. E.g., I_S.TABLES, I_S.SCHEMATA.
    See bug Bug#31195099 for more details.
    
    Change-Id: Ie8d309024316b694c210fbb660d55d4eb7afa05e
    d8453a0d
    Bug#30766181 I_S.KEY_COLUMN_USAGE IS VERY SLOW
    Gopal Shankar authored
    Bug#30216864 INFORMATION_SCHEMA.KEY_COLUMN_USAGE PERFORMANCE IS SLOW
    
    Problem:
    The system views INFORMATION_SCHEMA.KEY_COLUMN_USAGE and
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS uses UNION. This causes the
    conditions to be evaluated once per each SELECT statement which
    are part of UNION.  This causes dictionary metadata to be
    traversed multiple times. Mainly the metadata tables mysql.schema
    and mysql.tables would be traversed multiple times. And this
    intern causes the access checks for SQL objects to be done
    multiple times.
    
    Fix:
    Rewrite the system views for INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    and INFORMATION_SCHEMA.TABLE_CONSTRAINTS to move UNION into a
    LATERAL table. That way, it is be possible to merge the view and
    the conditions on schema name and table name is applied before
    the lateral table is executed, enabling indexes of the specified
    table to be accessed.
    
    There is following change in behavior with this patch. The column
    names of two INFORMATION_SCHEMA tables would be presented as
    capitalized column names and not the case provided by user in the
    query.
    
    E.g.,
      SELECT Table_Name, Constraint_name
        FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS (or KEY_COLUMN_USAGE) LIMIT 1;
      TABLE_NAME      CONSTRAINT_NAME
      ...
    
      Unlike, the behavior before patch is that we get user provided case,
    
      SELECT Table_Name, Constraint_name
        FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS (or KEY_COLUMN_USAGE) LIMIT 1;
      Table_Name      Constraint_name
      ...
    
    The new behavior is same as seen in other INFORMATION_SCHEMA
    tables based on system view. E.g., I_S.TABLES, I_S.SCHEMATA.
    See bug Bug#31195099 for more details.
    
    Change-Id: Ie8d309024316b694c210fbb660d55d4eb7afa05e
Loading