(self, cursor, schema, explain_state_cache_key)
Try to use the schema (if provided), caching errors to avoid excessive futile re-attempts
Try to use the schema (if provided), caching errors to avoid excessive futile re-attempts
Try to use the schema ( if provided ) caching errors to avoid excessive futile re - attempts
def _use_schema(self, cursor, schema, explain_state_cache_key):
        """
        Try to use the schema (if provided), caching errors to avoid excessive futile re-attempts
        """
        cached_state = self._collection_strategy_cache.get(explain_state_cache_key, EMPTY_EXPLAIN_STATE)
        if cached_state.error_code:
            return cached_state
        try:
            # If there was a default schema when this query was run, then switch to it before trying to collect
            # the execution plan. This is necessary when the statement uses non-fully qualified tables
            # e.g. `select * from mytable` instead of `select * from myschema.mytable`
            if schema:
                self._cursor_run(cursor, 'USE `{}`'.format(schema))
                return None
        except pymysql.err.DatabaseError as e:
            if len(e.args) != 2:
                raise
            error_state = ExplainState(
                strategy=None,
                error_code=DBExplainErrorCode.use_schema_error,
                error_message=str(type(e)),
            )
            if e.args[0] in PYMYSQL_NON_RETRYABLE_ERRORS:
                self._collection_strategy_cache[explain_state_cache_key] = error_state
            return error_state
def _use_schema ( self , cursor , schema , explain_state_cache_key ) : cached_state = self . _collection_strategy_cache . get ( explain_state_cache_key , EMPTY_EXPLAIN_STATE ) if cached_state . error_code : return cached_state try : # If there was a default schema when this query was run, then switch to it before trying to collect # the execution plan. This is necessary when the statement uses non-fully qualified tables # e.g. `select * from mytable` instead of `select * from myschema.mytable` if schema : self . _cursor_run ( cursor , 'USE `{}`' . format ( schema ) ) return None except pymysql . err . DatabaseError as e : if len ( e . args ) != 2 : raise error_state = ExplainState ( strategy = None , error_code = DBExplainErrorCode . use_schema_error , error_message = str ( type ( e ) ) , ) if e . args [ 0 ] in PYMYSQL_NON_RETRYABLE_ERRORS : self . _collection_strategy_cache [ explain_state_cache_key ] = error_state return error_state