func (rqc *RequestContext) execStreamSQL(conn dbconnpool.PoolConnection, sql string, callback func(*mproto.QueryResult) error) { start := time.Now() err := conn.ExecuteStreamFetch(sql, callback, int(rqc.qe.streamBufferSize.Get())) rqc.logStats.AddRewrittenSql(sql, start) if err != nil { panic(NewTabletErrorSql(FAIL, err)) } }
func (ti *TableInfo) fetchColumns(conn dbconnpool.PoolConnection) error { columns, err := conn.ExecuteFetch(fmt.Sprintf("describe `%s`", ti.Name), 10000, false) if err != nil { return err } for _, row := range columns.Rows { ti.AddColumn(row[0].String(), row[1].String(), row[4], row[5].String()) } return nil }
func (ti *TableInfo) fetchIndexes(conn dbconnpool.PoolConnection) error { indexes, err := conn.ExecuteFetch(fmt.Sprintf("show index from `%s`", ti.Name), 10000, false) if err != nil { return err } var currentIndex *schema.Index currentName := "" for _, row := range indexes.Rows { indexName := row[2].String() if currentName != indexName { currentIndex = ti.AddIndex(indexName) currentName = indexName } var cardinality uint64 if !row[6].IsNull() { cardinality, err = strconv.ParseUint(row[6].String(), 0, 64) if err != nil { log.Warningf("%s", err) } } currentIndex.AddColumn(row[4].String(), cardinality) } if len(ti.Indexes) == 0 { return nil } pkIndex := ti.Indexes[0] if pkIndex.Name != "PRIMARY" { return nil } ti.PKColumns = make([]int, len(pkIndex.Columns)) for i, pkCol := range pkIndex.Columns { ti.PKColumns[i] = ti.FindColumn(pkCol) } // Primary key contains all table columns for _, col := range ti.Columns { pkIndex.DataColumns = append(pkIndex.DataColumns, col.Name) } // Secondary indices contain all primary key columns for i := 1; i < len(ti.Indexes); i++ { for _, c := range ti.Indexes[i].Columns { ti.Indexes[i].DataColumns = append(ti.Indexes[i].DataColumns, c) } for _, c := range pkIndex.Columns { // pk columns may already be part of the index. So, // check before adding. if ti.Indexes[i].FindDataColumn(c) != -1 { continue } ti.Indexes[i].DataColumns = append(ti.Indexes[i].DataColumns, c) } } return nil }
func (rqc *RequestContext) execSQLNoPanic(conn dbconnpool.PoolConnection, sql string, wantfields bool) (*mproto.QueryResult, error) { if qd := rqc.qe.connKiller.SetDeadline(conn.Id(), rqc.deadline); qd != nil { defer qd.Done() } start := time.Now() result, err := conn.ExecuteFetch(sql, int(rqc.qe.maxResultSize.Get()), wantfields) rqc.logStats.AddRewrittenSql(sql, start) if err != nil { return nil, NewTabletErrorSql(FAIL, err) } return result, nil }