Docsity

Utilities and Queries - Lecture Notes | EECS 484, Study notes of Database Management Systems (DBMS)

Partial preview of the text

Download Utilities and Queries - Lecture Notes | EECS 484 and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

Minirel

Part

Utilities

and

Queries

…And

then

there

was

one.

EECS

Winter

Design

the

whole

System!

Create tables - Insert records into tables - Query the tables

This

time,

we

give

you

the

Buffer

Manager!

… sort of

Minirel

Architecture

You

have…

Sort - Hash Indexing - Buffer Manager - Relation and Attribute Catalog definitions

Classes

for

Catalogs

RelDesc: attributes, indexes on a relation typedef struct { char relName[MAXNAME]; // relation name int attrCnt; // number of attributes int indexCnt; // number of indexed attrs } RelDesc; class RelCatalog : public HeapFileScan { public: // get relation descriptor for a relation const Status getInfo(const string & rName, RelDesc& record); // add information to catalog const Status addInfo(RelDesc & record); …

Classes

for

Catalogs

AttrDesc: Attribute Description typedef struct { char relName[MAXNAME]; // relation name char attrName[MAXNAME]; // attribute name int attrOffset; // attribute offset int attrType; // attribute type int attrLen; // attribute length int indexed; // TRUE if indexed } AttrDesc; class AttrCatalog : public HeapFileScan { public: // get attribute catalog tuple const Status getInfo(const string & rName, const string & attrName, AttrDesc &record); // add information to catalog const Status addInfo(AttrDesc & record); // get all attributes of a relation const Status getRelInfo(const string & rName, int &attrCnt, AttrDesc *&attrs); …

INSERT INTO RELNAME(ATTRNAMELIST) VALUES (VALUELIST)

const Status Updates::Insert(const string & relation, const int attrCnt, const attrInfo attrList[] ) typedef struct { char relName[MAXNAME]; // relation name char attrName[MAXNAME]; // attribute name int attrType; // INTEGER, FLOAT, or STRING int attrLen; // length of attribute in bytes void *attrValue; // ptr to binary value (used // by the parser for insert into // statements) } attrInfo;

INSERT INTO RELNAME(ATTRNAMELIST) VALUES (VALUELIST)

const Status Updates::Insert(const string & relation, const int attrCnt, const attrInfo attrList[] ) typedef struct { char relName[MAXNAME]; // relation name char attrName[MAXNAME]; // attribute name int attrType; // INTEGER, FLOAT, or STRING int attrLen; // length of attribute in bytes void *attrValue; // ptr to binary value (used // by the parser for insert into // statements) } attrInfo;

Select

Queries

The “WHERE relation.attr > 2” kind - 2 access methods - File Scan - Index Scan - “Optimization” - Hash Indexing used - So index scan, when index and equality - Issues - No WHERE clause, then attribute list is NULL - Result stored in result relation

Select

Queries

static Status Select(const string

result, // name of the output relation const int projCnt, // number of attributes in the projection const attrInfo projNames[], // the list of projection attributes const attrInfo *attr, // attribute used in the selection predicate const Operator op, // predicate operation const void *attrValue); // literal value in the predicate

Sort Merge

k

80% of available buffers - n = number of tuples that can fit on the k buffers - Use Heapfilescan, storing n tuples at a time - Sort tuples, store in temporary files [runs] - Merge all temporary files, upto k Heapfilescans - Issues

Duplicates

[back

and

forth]

Result

stored

in

result

Bootstrapping

Catalogs

attrcat and relcat are relations - You must add data for themselves into the tables - 2 records into relcat - A record for each attribute of the relations into attrcat [ = 3 + 6 ]

Checklist

1. insert.cpp : Inserting tuples 2. query.h : Selects and the joins 3. select.cpp : Call the appropriate select algorithm. 4. scanselect.cpp : Select using a file scan 5. indexselect.cpp : Index selection 6. join.cpp: Pick the appropriate join algorithm 7. snl.cpp : Simple nested loop algorithm. 8. inl.cpp : Index nested loops algorithm 9. smj.cpp : sort merge join 10. dbcreate.cpp : Bootstrapping the catalogs

Use

sort.h,

sort.cpp

Good

Luck!