Esempio n. 1
0
func GetSqlExecPlan(sql string, getTable TableGetter, alloc arena.ArenaAllocator) (plan *ExecPlan, err error) {
	statement, err := sqlparser.Parse(sql, alloc)
	if err != nil {
		return nil, err
	}
	plan, err = analyzeSQL(statement, getTable, alloc)
	if err != nil {
		return nil, err
	}
	if plan.PlanId == PLAN_PASS_DML {
		log.Warningf("PASS_DML: %s", sql)
	}
	return plan, nil
}
Esempio n. 2
0
func (c *Conn) handleQuery(sql string) (err error) {
	sql = strings.TrimRight(sql, ";")
	stmt, err := sqlparser.Parse(sql, c.alloc)
	if err != nil {
		log.Warning(c.connectionId, sql, err)
		return c.handleShow(stmt, sql, nil)
	}

	log.Debugf("connectionId: %d, statement %T , %s", c.connectionId, stmt, sql)

	switch v := stmt.(type) {
	case *sqlparser.Select:
		c.server.IncCounter("select")
		return c.handleSelect(v, sql, nil)
	case *sqlparser.Insert:
		c.server.IncCounter("insert")
		return c.handleExec(stmt, sql, nil, true)
	case *sqlparser.Replace:
		c.server.IncCounter("replace")
		return c.handleExec(stmt, sql, nil, false)
	case *sqlparser.Update:
		c.server.IncCounter("update")
		return c.handleExec(stmt, sql, nil, false)
	case *sqlparser.Delete:
		c.server.IncCounter("delete")
		return c.handleExec(stmt, sql, nil, false)
	case *sqlparser.Set:
		c.server.IncCounter("set")
		return c.handleSet(v, sql)
	case *sqlparser.SimpleSelect:
		c.server.IncCounter("simple_select")
		return c.handleSimpleSelect(sql, v)
	case *sqlparser.Begin:
		c.server.IncCounter("begin")
		return c.handleBegin()
	case *sqlparser.Commit:
		c.server.IncCounter("commit")
		return c.handleCommit()
	case *sqlparser.Rollback:
		c.server.IncCounter("rollback")
		return c.handleRollback()
	case *sqlparser.Other:
		c.server.IncCounter("other")
		log.Warning(sql)
		return c.handleShow(stmt, sql, nil)
	default:
		return errors.Errorf("statement %T not support now, %+v, %s", stmt, stmt, sql)
	}
}
Esempio n. 3
0
func DDLParse(sql string, alloc arena.ArenaAllocator) (plan *DDLPlan) {
	statement, err := sqlparser.Parse(sql, alloc)
	if err != nil {
		return &DDLPlan{Action: ""}
	}
	stmt, ok := statement.(*sqlparser.DDL)
	if !ok {
		return &DDLPlan{Action: ""}
	}
	return &DDLPlan{
		Action:    stmt.Action,
		TableName: string(stmt.Table),
		NewName:   string(stmt.NewName),
	}
}