-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
arjunsk
committed
Dec 17, 2022
1 parent
c3f4d76
commit bf35a46
Showing
16 changed files
with
174 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/edu/utdallas/tiny_db/server/b_query_engine/common/catalog/MetadataMgr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 68 additions & 68 deletions
136
src/main/java/edu/utdallas/tiny_db/server/b_query_engine/common/catalog/index/IndexMgr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,87 @@ | ||
package edu.utdallas.tiny_db.server.b_query_engine.common.catalog.index; | ||
|
||
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.StatMgr; | ||
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.domain.StatInfo; | ||
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.StatMgr; | ||
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.domain.StatInfo; | ||
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableDefinition; | ||
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableMgr; | ||
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TablePhysicalLayout; | ||
import edu.utdallas.tiny_db.server.d_storage_engine.common.transaction.Transaction; | ||
import edu.utdallas.tiny_db.server.d_storage_engine.impl.data.heap.HeapRWRecordScan; | ||
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TablePhysicalLayout; | ||
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableDefinition; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* The index manager. | ||
* The index manager has similar functionality to the table manager. | ||
* The index manager. The index manager has similar functionality to the table manager. | ||
* | ||
* @author Edward Sciore | ||
*/ | ||
public class IndexMgr { | ||
private TablePhysicalLayout recordValueLayout; | ||
private TableMgr tblmgr; | ||
private StatMgr statmgr; | ||
|
||
/** | ||
* Create the index manager. | ||
* This constructor is called during system startup. | ||
* If the database is new, then the <i>idxcat</i> table is created. | ||
* | ||
* @param isnew indicates whether this is a new database | ||
* @param tx the system startup transaction | ||
*/ | ||
public IndexMgr(boolean isnew, TableMgr tblmgr, StatMgr statmgr, Transaction tx) { | ||
if (isnew) { | ||
TableDefinition sch = new TableDefinition(); | ||
sch.addStringField("indexname", TableMgr.MAX_NAME); | ||
sch.addStringField("tablename", TableMgr.MAX_NAME); | ||
sch.addStringField("fieldname", TableMgr.MAX_NAME); | ||
tblmgr.createTable("idxcat", sch, tx); | ||
} | ||
this.tblmgr = tblmgr; | ||
this.statmgr = statmgr; | ||
recordValueLayout = tblmgr.getLayout("idxcat", tx); | ||
} | ||
private TablePhysicalLayout recordValueLayout; | ||
private TableMgr tblmgr; | ||
private StatMgr statmgr; | ||
|
||
/** | ||
* Create the index manager. This constructor is called during system startup. If the database is | ||
* new, then the <i>idxcat</i> table is created. | ||
* | ||
* @param isnew indicates whether this is a new database | ||
* @param tx the system startup transaction | ||
*/ | ||
public IndexMgr(boolean isnew, TableMgr tblmgr, StatMgr statmgr, Transaction tx) { | ||
if (isnew) { | ||
TableDefinition sch = new TableDefinition(); | ||
sch.addStringField("indexname", TableMgr.MAX_NAME); | ||
sch.addStringField("tablename", TableMgr.MAX_NAME); | ||
sch.addStringField("fieldname", TableMgr.MAX_NAME); | ||
|
||
/** | ||
* Create an index of the specified type for the specified field. | ||
* A unique ID is assigned to this index, and its information | ||
* is stored in the idxcat table. | ||
* | ||
* @param idxname the name of the index | ||
* @param tblname the name of the indexed table | ||
* @param fldname the name of the indexed field | ||
* @param tx the calling transaction | ||
*/ | ||
public void createIndex(String idxname, String tblname, String fldname, Transaction tx) { | ||
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout); | ||
ts.seekToInsertStart(); | ||
ts.setString("indexname", idxname); | ||
ts.setString("tablename", tblname); | ||
ts.setString("fieldname", fldname); | ||
ts.close(); | ||
tblmgr.createTable("idxcat", sch, tx); | ||
} | ||
this.tblmgr = tblmgr; | ||
this.statmgr = statmgr; | ||
recordValueLayout = tblmgr.getLayout("idxcat", tx); | ||
} | ||
|
||
/** | ||
* Create an index of the specified type for the specified field. A unique ID is assigned to this | ||
* index, and its information is stored in the idxcat table. | ||
* | ||
* @param idxname the name of the index | ||
* @param tblname the name of the indexed table | ||
* @param fldname the name of the indexed field | ||
* @param tx the calling transaction | ||
*/ | ||
public void createIndex(String idxname, String tblname, String fldname, Transaction tx) { | ||
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout); | ||
ts.seekToInsertStart(); | ||
ts.setString("indexname", idxname); | ||
ts.setString("tablename", tblname); | ||
ts.setString("fieldname", fldname); | ||
ts.close(); | ||
} | ||
|
||
/** | ||
* Return a map containing the index info for all indexes on the specified table. | ||
* | ||
* @param tblname the name of the table | ||
* @param tx the calling transaction | ||
* @return a map of IndexInfo objects, keyed by their field names | ||
*/ | ||
public Map<String, IndexInfo> getIndexInfo(String tblname, Transaction tx) { | ||
Map<String, IndexInfo> result = new HashMap<String, IndexInfo>(); | ||
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout); | ||
while (ts.next()) { | ||
if (ts.getString("tablename").equals(tblname)) { | ||
String idxname = ts.getString("indexname"); | ||
String fldname = ts.getString("fieldname"); | ||
TablePhysicalLayout tblRecordValueLayout = tblmgr.getLayout(tblname, tx); | ||
StatInfo tblsi = statmgr.getStatInfo(tblname, tblRecordValueLayout, tx); | ||
|
||
/** | ||
* Return a map containing the index info for all indexes | ||
* on the specified table. | ||
* | ||
* @param tblname the name of the table | ||
* @param tx the calling transaction | ||
* @return a map of IndexInfo objects, keyed by their field names | ||
*/ | ||
public Map<String, IndexInfo> getIndexInfo(String tblname, Transaction tx) { | ||
Map<String, IndexInfo> result = new HashMap<String, IndexInfo>(); | ||
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout); | ||
while (ts.next()) if (ts.getString("tablename").equals(tblname)) { | ||
String idxname = ts.getString("indexname"); | ||
String fldname = ts.getString("fieldname"); | ||
TablePhysicalLayout tblRecordValueLayout = tblmgr.getLayout(tblname, tx); | ||
StatInfo tblsi = statmgr.getStatInfo(tblname, tblRecordValueLayout, tx); | ||
IndexInfo ii = new IndexInfo(idxname, fldname, tblRecordValueLayout.schema(), tx, tblsi); | ||
result.put(fldname, ii); | ||
} | ||
ts.close(); | ||
return result; | ||
IndexInfo ii = new IndexInfo(idxname, fldname, tblRecordValueLayout.schema(), tx, tblsi); | ||
result.put(fldname, ii); | ||
} | ||
} | ||
ts.close(); | ||
return result; | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...e/impl/basic/b_stats_manager/StatMgr.java → ..._engine/common/catalog/stats/StatMgr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...asic/b_stats_manager/domain/StatInfo.java → ...common/catalog/stats/domain/StatInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.