public TableInfo getTableInfo(string tblname, Transaction tx) { RecordFile tcatfile = new RecordFile(tcatInfo, tx); int reclen = -1; while (tcatfile.next()) { if (tcatfile.getString("tblname").Equals(tblname)) {//获取到指定表名称的一条记录长度 reclen = tcatfile.getInt("reclength"); break; } } tcatfile.close(); RecordFile fcatfile = new RecordFile(fcatInfo, tx); Schema sch = new Schema(); Dictionary <string, int> offsets = new Dictionary <string, int>(); while (fcatfile.next()) {//每次取fcatfile中的一条记录 if (fcatfile.getString("tblname").Equals(tblname)) { string fldname = fcatfile.getString("fldname"); int fldtype = fcatfile.getInt("type"); int fldlen = fcatfile.getInt("length"); int offset = fcatfile.getInt("offset"); offsets.Add(fldname, offset); //获取一张表中每个字段名称的偏移量 sch.addField(fldname, fldtype, fldlen); //获取一张表的模式信息 } } fcatfile.close(); return(new TableInfo(tblname, sch, offsets, reclen)); }
private StatInfo calcTableStats(TableInfo ti, Transaction tx) { lock (threadLock) { int numRecs = 0; RecordFile rf = new RecordFile(ti, tx); int numblocks = 0; while (rf.next()) { numRecs++; numblocks = rf.currentRid().blockNumber() + 1; } rf.close(); return(new StatInfo(numblocks, numRecs)); } }
public string getViewDef(string vname, Transaction tx) { string result = null; TableInfo ti = tblMgr.getTableInfo("viewcat", tx); RecordFile rf = new RecordFile(ti, tx); while (rf.next()) { if (rf.getString("viewdef").Equals(vname)) { result = rf.getString("viewdef"); break; } } rf.close(); return(result); }
private void refreshStatistics(Transaction tx) { lock (threadLock) { tablestats = new Dictionary <string, StatInfo>(); numcalls = 0; TableInfo tcatmd = tblMgr.getTableInfo("tblcat", tx); //获取tblcat表中的信息 RecordFile tcatfile = new RecordFile(tcatmd, tx); //利用这些信息新建一个RecordFile读取类 while (tcatfile.next()) { //获取每一张表的字段信息,计算出块数和记录数,添加到统计信息管理器中去 string tblname = tcatfile.getString("tblname"); TableInfo md = tblMgr.getTableInfo(tblname, tx); StatInfo si = calcTableStats(md, tx); tablestats.Add(tblname, si); } tcatfile.close(); } }
public Dictionary <string, IndexInfo> getIndexInfo(string tblname, Transaction tx) {//返回一个映射,包含了指定表中所有索引的信息 Dictionary <string, IndexInfo> result = new Dictionary <string, IndexInfo>(); RecordFile rf = new RecordFile(ti, tx); while (rf.next()) { if (rf.getString("tablename").Equals(tblname)) { string idxname = rf.getString("indexname"); string fldname = rf.getString("fieldname"); IndexInfo ii = new IndexInfo(idxname, tblname, fldname, tx); result.Add(fldname, ii); } } rf.close(); return(result); }
public bool next() { return(rf.next()); }