Search in sources :

Example 11 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class PGSchemaStatVisitor method visit.

@Override
public boolean visit(PGInsertStatement x) {
    setAliasMap();
    if (x.getWith() != null) {
        x.getWith().accept(this);
    }
    x.putAttribute("_original_use_mode", getMode());
    setMode(x, Mode.Insert);
    String originalTable = getCurrentTable();
    if (x.getTableName() instanceof SQLName) {
        String ident = ((SQLName) x.getTableName()).toString();
        setCurrentTable(ident);
        x.putAttribute("_old_local_", originalTable);
        TableStat stat = getTableStat(ident);
        stat.incrementInsertCount();
        Map<String, String> aliasMap = getAliasMap();
        if (aliasMap != null) {
            if (x.getAlias() != null) {
                aliasMap.put(x.getAlias(), ident);
            }
            aliasMap.put(ident, ident);
        }
    }
    accept(x.getColumns());
    accept(x.getQuery());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 12 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class PGSchemaStatVisitor method visit.

@Override
public boolean visit(PGUpdateStatement x) {
    Map<String, String> oldAliasMap = getAliasMap();
    setAliasMap();
    if (x.getWith() != null) {
        x.getWith().accept(this);
    }
    String ident = x.getTableName().toString();
    setCurrentTable(ident);
    TableStat stat = getTableStat(ident);
    stat.incrementUpdateCount();
    accept(x.getFrom());
    Map<String, String> aliasMap = getAliasMap();
    aliasMap.put(ident, ident);
    accept(x.getItems());
    accept(x.getWhere());
    setAliasMap(oldAliasMap);
    return false;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Example 13 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class SchemaStatVisitor method visit.

@Override
public boolean visit(SQLAlterTableDropIndex x) {
    SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
    String tableName = stmt.getName().toString();
    TableStat tableStat = this.getTableStat(tableName);
    tableStat.incrementDropIndexCount();
    return false;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Example 14 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class SchemaStatVisitor method visit.

@Override
public boolean visit(SQLDropIndexStatement x) {
    setMode(x, Mode.DropIndex);
    SQLExprTableSource table = x.getTableName();
    if (table != null) {
        SQLName name = (SQLName) table.getExpr();
        String ident = name.toString();
        setCurrentTable(ident);
        TableStat stat = getTableStat(ident);
        stat.incrementDropIndexCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, ident, ident);
    }
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 15 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class SchemaStatVisitor method visit.

@Override
public boolean visit(SQLMergeStatement x) {
    setAliasMap();
    String originalTable = getCurrentTable();
    setMode(x.getUsing(), Mode.Select);
    x.getUsing().accept(this);
    setMode(x, Mode.Merge);
    String ident = x.getInto().toString();
    setCurrentTable(x, ident);
    x.putAttribute("_old_local_", originalTable);
    TableStat stat = getTableStat(ident);
    stat.incrementMergeCount();
    Map<String, String> aliasMap = getAliasMap();
    if (aliasMap != null) {
        if (x.getAlias() != null) {
            putAliasMap(aliasMap, x.getAlias(), ident);
        }
        putAliasMap(aliasMap, ident, ident);
    }
    x.getOn().accept(this);
    if (x.getUpdateClause() != null) {
        x.getUpdateClause().accept(this);
    }
    if (x.getInsertClause() != null) {
        x.getInsertClause().accept(this);
    }
    return false;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Aggregations

TableStat (com.alibaba.druid.stat.TableStat)45 SQLName (com.alibaba.druid.sql.ast.SQLName)21 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)10 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)9 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)9 SQLUtils (com.alibaba.druid.sql.SQLUtils)6 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)4 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)3 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)3 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)3 Mode (com.alibaba.druid.stat.TableStat.Mode)2 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)1 SQLAlterTableItem (com.alibaba.druid.sql.ast.statement.SQLAlterTableItem)1 SQLDropIndexStatement (com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement)1 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)1 Name (com.alibaba.druid.stat.TableStat.Name)1 Map (java.util.Map)1