func (si *SchemaInfo) GetPlan(logStats *sqlQueryStats, sql string) (plan *ExecPlan) { log.Warn("plan sql %v", sql) si.mu.Lock() defer si.mu.Unlock() if plan := si.getQuery(sql); plan != nil { return plan } var tableInfo *schema.Table GetTable := func(tableName string) (table *schema.Table, ok bool) { tableInfo, ok = si.tables[tableName] if !ok { return nil, false } return tableInfo, true } splan, err := sqlparser.ExecParse(sql, GetTable) if err != nil { log.Info("parse error %v", err.Error()) panic(NewTabletError(FAIL, "%s", err)) } plan = &ExecPlan{ExecPlan: splan, Table: tableInfo} if plan.PlanId.IsSelect() { fields := make([]eproto.Field, len(plan.ColumnNumbers)) for i, cIdx := range plan.ColumnNumbers { column := si.tables[plan.TableName].Columns[cIdx] fields[i] = eproto.Field{column.Name, int64(column.Category)} } plan.Fields = fields } else if plan.PlanId == sqlparser.PLAN_DDL || plan.PlanId == sqlparser.PLAN_SET { return plan } si.queries.Set(sql, plan) return plan }
func (si *SchemaInfo) GetPlan(logStats *sqlQueryStats, sql string) (plan *ExecPlan) { si.mu.Lock() defer si.mu.Unlock() if plan := si.getQuery(sql); plan != nil { return plan } var tableInfo *schema.Table GetTable := func(tableName string) (table *schema.Table, ok bool) { tableInfo, ok = si.tables[tableName] if !ok { return nil, false } return tableInfo, true } splan, err := sqlparser.ExecParse(sql, GetTable) if err != nil { panic(NewTabletError(FAIL, "%s", err)) } plan = &ExecPlan{ExecPlan: splan, Table: tableInfo} // plan.Rules = si.rules.filterByPlan(sql, plan.PlanId) /* if plan.PlanId.IsSelect() { if plan.FieldQuery == nil { log.Warn("Cannot cache field info: %s", sql) } else { sql := plan.FieldQuery.Query //TODO // r, err := si.executor(sql, 1, true) logStats.QuerySources |= QUERY_SOURCE_DBENGINE logStats.NumberOfQueries += 1 logStats.AddRewrittenSql(sql) if err != nil { panic(NewTabletError(FAIL, "Error fetching fields: %v", err)) } plan.Fields = r.Fields } } else if plan.PlanId == sqlparser.PLAN_DDL || plan.PlanId == sqlparser.PLAN_SET { return plan }*/ si.queries.Set(sql, plan) return plan }