Indexing and Hashing Course outlines Introduction Basic Concepts
Indexing and Hashing Course outlines Introduction Basic Concepts Ordered Indexes-Clustered / Unclustered Multi-level Indexes Index Update: Deletion / Insertion B+-Tree Index Files, B-Tree Index Files Example of a B+-tree - Insert / Delete Static Hashing / Dynamic Hashing Example of Hash Index Hashing vs. Other Schemes Grid Files Bitmap Indices Index Definition in SQL
Introduction Indexing mechanisms used to speed up access to desired data. e. g. : author catalog in library Ê An index on a file speeds up selections on the search key fields for the index. Ê Any subset of the fields of a relation can be the search key for an index on the relation. Ê Search key is not the same as key (minimal set of fields that uniquely identify a record in a relation). Ê An index contains a collection of data entries, and supports efficient retrieval of all data entries k* with a given key value k. 2
Indexing Basic Concepts Ê Search Key: attribute to set of attributes used to look up records in a file. Ê Three alternatives data entries in index: ü Data record with key value k ü <k, rid of data record with search key value k> ü <k, list of rids of data records with search key k> Ê An index file: Ê consists of records (called index entries) of the form < search-key value, pointer > Pointer designates the location of desired data Ê is typically much smaller than the original file Ê Two basic kinds of indices: 1. 2. Ordered indices: search keys are stored in sorted order Hash indices: search keys are distributed uniformly across “buckets” using a “hash function”. Ê Index Evaluation Metrics: Ê Access types supported efficiently. Ê E. g. , records with a specified value in the attribute ( equality) Ê or records with an attribute value falling in a specified range of values (between). Ê Access time, Insertion time, Deletion time 3
Two basic kinds of indices: Ordered indexes Ordered Indexes ÊIn an ordered index, index entries are stored sorted on the search key value. E. g. , author catalog in library. ÊTwo basic classes of indexes: ÊPrimary index: in a sequentially ordered file, the index whose search key specifies the sequential order of the file. Ê Also called clustering index Ê The search key of a primary index is usually, but not necessarily, the primary key. ÊSecondary index: an index whose search key specifies an order different from the sequential order of the file. Also called nonclustering or logical index. C Notion: Index-sequential file: ordered sequential file with a primary index. 4
Two basic kinds of indices: Ordered indices Clustered vs. Unclustered Index Suppose that <k, rid of data record with search key value k> is used for data entries, and that the data records are stored in a Heap file. Ê To build clustered index, first sort the Heap file. Ê Overflow pages may be needed for inserts. Clustered Un. Clustered Index entries direct search for data entries Data entries (Index File) (Data file) Data Records 5
Two basic kinds of indices: Ordered indices Dense vs. Sparse Index Ê Dense index: Index record appears for every search-key value in the file. Ê Sparse Index: contains index records for only some search-key values. C Applicable when records are sequentially ordered on search-key Ê To locate a record with search-key value K we: Ê Find index record with largest “search-key Ê Search file sequentially starting at the record to which the index record points value < K” Ashby, 25, 3000 22 Basu, 33, 4003 ° Less space and less maintenance Ashby overhead for insertions and deletions. Bristow, 30, 2007 Cass, 5004 Smith Daniels, 22, 6003 25 30 33 40 44 Jones, 40, 6003 44 Smith, 44, 3000 50 Tracy, 44, 5004 Sparse Index on Name Data File ° Generally slower than dense index for locating records. ° Good tradeoff: sparse index with an index entry for every corresponding to least search-key value in the block. Dense Index on Age block in file, 6
Indexes as Access Paths :
Types of Single-Level Indexes: Primary / Secondary Primary index on the ordering key field : Primary Index EMPLOYEE(NAME, SSN, . . . ) Ê Defined on an ordered data file Ê The data file is ordered on a key field Ê Includes one index entry for each block in the data file; the index entry has the key field value for the first record in the block, which is called the block anchor Ê A similar scheme can use the last record in a block. Ê A primary index is a nondense (sparse) index, since it includes an entry for each disk block of the data file and the keys of its anchor record rather than for every search value. Binary search needs = log 2 b = log 23000 = 12 block accesses Size of index entry Ri = V+P= (9+6)=15 bytes Bfri = B/Ri = (1024/15) = 68 entries/block bi= (ri/bfri) = (3000/68 = 45 index blocks Binary search needs = log 2 bi = log 245 = 6 block accesses 8
Types of Single-Level Indexes: Primary / Secondary Clustering index on a ordering non-key field : EMPLOYEE(NAME, SSN, . . . ) Clustering Index Ê Defined on an ordered data file Ê The data file is ordered on a nonkey field unlike primary index, which requires that the ordering field of the data file have a distinct value for each record. Ê Includes one index entry for each distinct value of the field; the index entry points to the first data block that contains records with that field value. C It is another example of non-dense index where Insertion and Deletion is relatively straightforward with a clustering index. A clustering index on the Dept_number ordering nonkey field of an EMPLOYEE file 9
Types of Single-Level Indexes: Primary / Secondary Clustering index- another example : EMPLOYEE(NAME, SSN, . . . ) Clustering index with a separate block cluster for each group of records that share the same value for the clustering field. 10
Types of Single-Level Indexes: Primary / Secondary Dense secondary index on a non-ordering key field : EMPLOYEE(NAME, SSN, . . . ) Secondary Index Ê A secondary index provides a secondary means of accessing a file for which some primary access already exists. Ê The secondary index may be on a field which is a candidate key and has a unique value in every record, or a non-key with duplicate values. Ê The index is an ordered file with two fields. Ê The first field is of the same data type as some non-ordering field of the data file that is an indexing field. Ê The second field is either a block pointer or a record pointer. Ê There can be many secondary indexes (and hence, indexing fields) for the same file. A dense seconda ry index on a non -ordering key field of a file. 11
Types of Single-Level Indexes: Primary / Secondary index on a non-key field : Three schemes: Ê Several index entries with the same K(i) values. Dense index Ê Variable length records for the index entries (repeating pointer); e. g. <P(i, 1), …, P(i, k)> for K(i) Ê Create extra level to handle the multiple pointers A secondary index on a non-key field implemented using one level of indirection so that index entries are of fixed length and have unique 12
Multi-level Indexes Ê If primary index does not fit in memory, access becomes expensive. Ê To reduce number of disk accesses to index records, treat primary index kept on disk as a sequential/ordered file and construct a sparse index on it. Ê outer index – a sparse index of primary index Ê inner index – the primary index file ° If even outer index is too large to fit in main memory , yet another N Indices at all levels level of index can be created, and so on. must be updated on insertion or deletion from the file. outer index Non-leaf Pages Leaf Pages inner index Overflow Page Primary pages 13
Multi-Level Index A Two-level Primary Index : r=30, 000 fixed-length records, R=100 bytes, B=1, 024 bytes, and b= 3000 blocks. Linear search: b/2 = 3000/2 = 1500 block accesses Secondary index on a non-ordering key field: V=9 bytes, and P=6 bytes, Ri = (9+6) = 15 bytes bfri = B/Ri = 1024/15 = 68 entries/block ri = r since dense bi = ri/bfri = 3000/68 = 442 blocks Binary search needs: log 2 bi = log 2442 = 9 block accesses Total block accesses = 9 + 1 = 10 A two-level primary index resembling ISAM (Indexed Sequential Access Method) organization A multilevel index bfri = fo (fan-out) = 68 Number of first-level blocks b 1 = 442 blocks Number of second-level blocks b 2 = b 1/fo = 442/68 =7 blocks 14
Index Update: Deletion / Insertion Deletion: Ê If deleted record was the only record in the file with its particular search-key value, the search-key is deleted from the index also. Ê Single-level index deletion: B 0 Ê Dense indices – deletion of search-key is similar to file record deletion. Ê Sparse indices – if an entry for the search key exists in the index, it is deleted by replacing the entry in the index with the next search-key value in the file (in search-key order). If the next search-key value already has an index entry, the entry B is deleted instead of being replaced. M Insertion: Ê Single-level index insertion: Ê Perform a lookup using the search-key value appearing in the record to be inserted. Ê Dense indices – if the search-key value does not appear in the index, insert it. Ê Sparse indices – if index stores an entry for each block of the file, no change needs to be made to the index unless a new block is created. In this case, the first search-key value appearing in the new block is inserted into the index. B 0 B 1 Re d B 2 … … B 75 … D 50 … D 60 B 1 … M 70 … P 40 … P 90 … P 70 B 2 … Red 70 … Rod 35 15
Primary and Secondary Indices Ê Secondary indices have to be dense. Ê Indices offer substantial benefits when searching for records. Ê When a file is modified: Ê every index on the file must be updated, Ê updating indices imposes overhead on database modification. Ê Sequential scanning: Ê sequential scan using primary index is efficient Ê but a sequential scan using a secondary index is expensive 16
Multi-Level Indexes / Tree structure Ê A multi-level index is a form of search tree Ê Insertion and deletion of new index entries is a severe problem because every level of the index is an ordered file. Ê Dynamic multilevel index: leaves some space in each of its block for inserting new entries Ê That is called B+-tree or B-tree Ê Dynamic Multilevel Indexes - Tree data structure Ê A tree is formed of nodes Ê Each node has one parent node (except root) and several child nodes. Ê A root does not have parent node Ê A leaf does not have child node Ê A subtree of a node consists of that node and all its descendant nodes 17
B+-Tree Index Files Ê B+-tree indexes are an alternative to indexedsequential files. Ê Disadvantage of indexed-sequential files: performance degrades as file grows, since many overflow blocks get created. Periodic reorganization of entire file is required. Ê Advantage of B+-tree index files: automatically reorganizes itself with small, local, changes, in the face of insertions and deletions. Reorganization of entire file is not required to maintain performance. Ê Disadvantage of B+-trees: extra insertion and deletion overhead, space overhead. Advantages of B+-trees outweigh disadvantages, and they are used extensively. ÊA B+-tree is a rooted tree satisfying the following properties: Ê All paths from root to leaf are of the same length Ê Each node that is not a root or a leaf has between [n/2] and n children, where n is the maximum number of pointers per node. Ê A leaf node has between [(n– 1)/2] and n– 1 values 18
B+-Tree of order p, typical node structures Each internal node is: Ê <P 1, K 1, P 2, K 2, …, Pq-1, Kq-1, Pq> , q p, each Pi is a tree pointer Ê Each internal node contains at most p-1 tree pointers Ê Each internal node has at least p/2 tree pointers Ê An internal node with q pointers q p, has q-1 search Typical internal node key values Ê The search-keys in a node are ordered: K 1 < K 2 < K 3 <. . . < Kn– 1 Ê For all values X in the subtree pointed at by Pi, we have: for 1<i<q: Ki-1 <X< Ki for i=1: X< Ki for i=q: Ki-1<X Typical leaf node Each leaf node is: Ê < <K 1, Pr 1>, <K 2, Pr 2>, …, <Kq-1, Prq-1>, Pnext>, q p, each Pri is a data pointer, and Pnext points to the next leaf node Ê The search-keys are ordered: K 1 < K 2 < K 3 <. . . < Kn– 1 19
Exercise : Calculate the order “p” of +-tree B Search key V=9 bytes, Block size B=512 bytes, Data pointer Pr=7 bytes, and Block pointer P=6 bytes Ê At most p tree pointers, and p-1 search key fields, which should be in a single block (p*P) + ((p-1)*V) B (p*6) + ((p-1)*9) 512 (15*p) 512 , Therefore p = 34 Ê The leaf node order pleaf (pleaf*(Pr+V)) + P B (pleaf*(7+9) + 6 512 (16* pleaf) 506 pleaf = 31 Construct the corresponding B+-tree – number of Entries Ê Assumption : each node of B-tree is 69% full Ê Each node will have 34 * 69/100 = 23 pointers, and 22 search key field values. Ê Each leaf node 69/100*pleaf = 69/100 * 31 21 data record pointer P Root: P Level 1: P Level 2: P Level 3: 1 node 23 nodes 529 nodes 12, 167 nodes 22 entries 23 pointers 506 entries 529 pointers 11, 638 entries 12, 167 pointers 255, 507 data record pointer 20
Example of a B+-tree for account file (n = 3) B+-tree for account file (n = 5) With n = 5 C Leaf nodes must have between 2 and 4 values ( (n– 1)/2 and n – 1) C Internal nodes must have between 3 and 5 children ( (n/2 and n with n =5). C Root must have at least 2 children. Ê Observations about B+-trees Ê Since the inter-node connections are done by pointers, “logically” close blocks need not be “physically” close. Ê The internal levels of the B+-tree form a hierarchy of sparse indices. Ê The B+-tree contains a relatively small number of levels (logarithmic in the size of the main file), thus searches can be conducted efficiently. Ê Insertions and deletions to the main file can be handled efficiently, as the index can be restructured in logarithmic time. 21
Queries on B+-Trees Find all records with a search-key value of k. 1. Start with the root node 1. Examine the node for the smallest search-key value > k. 2. If such a value exists, assume it is Kj. Then follow Pi to the child node 3. Otherwise k Km– 1, where there are m pointers in the node. Then follow P m to the child node. 2. If the node reached by following the pointer above is not a leaf node, repeat the above procedure on the node, and follow the corresponding pointer. 3. Eventually reach a leaf node. If for some i, key Ki = k follow pointer Pi to the desired record or bucket. Else no record with search-key value k exists. Ê In processing a query, a path is traversed in the tree from the root to some leaf node. Ê A node is generally the same size as a disk block, typically 4 kilobytes, and n is typically around 100 (40 bytes per index entry). Ê With 1 million search key values and n = 100, Ê at most log 50(1, 000) = 4 nodes are accessed in a lookup. Ê Contrast this with a balanced binary free “with 1 million search key values” — around 20 nodes are accessed in a lookup 22
Updates on B+-Trees: Insertion Ê Find the leaf node in which the search-key value would appear Ê If the search-key value is already there in the leaf node, record is added to file the bucket. and if necessary a pointer is inserted into Ê If the search-key value is not there, then add the record to the main file and create a bucket if necessary. Then: Ê If there is room in the leaf node, insert (key-value, pointer) pair in the leaf node Ê Otherwise, split the node (along with the new (key-value, pointer) entry) as discussed in the next slide. Ê Splitting a node: Ê take the n (search-key value, pointer) pairs (including the one being inserted) in sorted order. splitting node containing Brighton and Downtown on inserting Clearview Ê Place the first n/2 in the original node, Ê and the rest in a new node. Ê let the new node be p, and let k be the least key value in p. Insert (k, p) in the parent of the node being split. If the parent is full, split it and propagate the split further up. 23
Updates on B+-Trees: Deletion Ê Find the record to be deleted, and remove it from the main file and from the bucket (if present) Ê Remove (search-key value, pointer) from the leaf node if there is no bucket or if the bucket has become empty Ê If the node has too few entries due to the removal, and the entries in the node and a siblingfrère fit into a single node, then Ê Insert all the search-key values in the two nodes into a single node (the on the left), and delete the other node. Ê Delete the pair (Ki– 1, Pi), where Pi is the pointer to the deleted node, from its parent, recursively using the above procedure. Ê Otherwise, if the node has too few entries due to the removal, and the entries in the node and a sibling fit into a single node, then Ê Redistribute the pointers between the node and a sibling such that both have more than the minimum number of entries. Ê Update the corresponding search-key value in the parent of the node. Ê The node deletions may cascade upwards till a node which has n/2 or more pointers is found. If the root node has only one pointer after deletion, it is deleted and the sole child becomes the root. 24
Insertion with B+-tree (p = 3, pleaf = 2) Insertion sequence: 8, 5, 1, 7, 3, 12, 9, 6 Insert 8, 5, 1 Insert 9 Insert 6 Insert 7, 3 Done Insert 12 25
Deletion with B+-tree (sequence: 5, 12, 9) Delete 5 Delete 12 Delete 9 Done 26
B-Tree Index File structures Ê Similar to B+-tree, but B-tree allows search-key values to appear only once; eliminates redundant storage of search keys. Ê Search keys in internal nodes appear nowhere else in the B-tree; an additional pointer field for each search key in an internal node must be included. Ê Non-leaf node – pointers Pri are the bucket or file record pointers A typical B-tree internal node with q 1 search values A B-tree of order p=3 showing an inserted sequence: 8, 5, 1, 7, 3, 12, 9, 6. 27
Exercise : Calculate the order “p” of B -tree Search field V=9 bytes, Block size B=512 bytes, Data pointer Pr=7 bytes, and Block pointer P=6 bytes Ê At most p tree pointers, p-1 data pointers, and p-1 search key fields, which should be in a single block Ê (p*P) + ((p-1)*(Pr+V)) B (p*6) + ((p-1)*(7+9)) 512 (22*p) 528 Therefore p = 23 Construct the corresponding B-tree- Search field nonordering key field Each node of B-tree is 69 % full Ê Each node will have p*0. 69 = 23 * 0. 69 = 16 pointers, and 15 search key field values. fo = 15 P Root: P Level 1: P Level 2: P Level 3: 1 node 16 nodes 256 nodes 4096 nodes 15 entries 240 entries 3840 entries 61440 entries 16 pointers 256 pointers 4096 pointers Ê For example, 2 -level (3420+240+15=4095), or 3 -level (65, 535 entries) 28
B-Tree Index vs. B+-Tree B-tree B+-tree on same data Ê Advantages of B-Tree indices: Ê May use less tree nodes than a corresponding B+-Tree. Ê Sometimes possible to find search-key value before reaching leaf node. Ê Disadvantages of B-Tree indices: Ê Only small fraction of all search-key values are found early Ê Internal (nonleaf) nodes are larger, so fan-out is reduced. Thus B-Trees typically have greater depth than corresponding B+-Tree Ê Insertion and deletion more complicated than in B+-Trees Ê Implementation is harder than B+-Trees. C Typically, advantages of B-Trees do not out weigh disadvantages. 29
Static Hashing Ê A bucket is a unit of storage containing one or more records (a bucket is typically a disk block). Ê In a hash file organization we obtain the bucket of a record directly from its search-key value using a hash function. Hash file organization of account file, using branchname as key Hash function h : Ê is a function from the set of all search-key values K to the set of all bucket addresses B. K b=h(k) B Ê is used to locate records for access, insertion as well as deletion. Ê Records with different search-key values may be mapped to the same bucket; thus entire bucket has to be 30
Hash Functions Ê Worst has function maps all search-key values to the same bucket; this makes access time proportional to the number of search-key values in the file. Ê An ideal hash function is uniform, i. e. , each bucket is assigned the same number of search-key values from the set of all possible values. Ê Ideal hash function is random, so each bucket will have the same number of records assigned to it irrespective of the actual distribution of search-key values in the file. Ê Typical hash functions perform computation on the internal binary representation of the search-key. For example, for a string search-key, the binary representations of all the b 0 characters in the string could be added and the sum modulo the number of buckets “n” could be returned. Overflow chaining – the buckets of a Overflow buckets for bucket overflow 1 given bucket are bn chained together in a Handling of Bucket Overflows linked list. Ê Bucket overflow can occur because of ÊInsufficient buckets ÊSkew in distribution of records. This can occur due to two reasons: 1. multiple records have same search-key value 31 b 1
Hashing can be used not only for file organization, but also for indexstructure creation. A hash index organizes the search keys, with their associated record Hash Indices Ê pointers, into a hash file structure. Ê Strictly speaking, hash indices are always secondary indices Ê if the file itself is organized using hashing, a separate primary hash index on it using the same search-key is unnecessary. Ê However, we use the term hash index to refer to both secondary index structures and hash organized files. Primary hash B 0 Considered Bucket 0 table B 1 Bucket (A, B, C, D) Key 1=B h … 1 1 le hashed on Key 1=B Bucket n We use records of type (desired k, p ) Key 2=A h 2 Index on Key 2=A A 0 B 0 A 1 B 1 An example … A Bm m Secondary hashing 32
Deficiencies of Static Hashing Ê In static hashing, function h maps search-key values to a fixed set of B of bucket addresses. Ê Databases grow with time. If initial number of buckets is too small, performance will degrade due to too much overflows. Ê If file size at some point in the future is anticipated and number of buckets allocated accordingly, significant amount of space will be wasted initially. Ê If database shrinks, again space will be wasted. Ê One option is periodic re-organization function, but it is very expensive. of the file with a new hash Ê These problems can be avoided by using techniques that allow the number of buckets to be modified dynamically. Ê Good for database that grows and shrinks in size Ê Allows the hash function to be modified dynamically - Extendable hashing 33
Hashing vs. Other Schemes Extendable Hashing vs. Other Schemes Ê Benefits of extendable hashing: Ê Hash performance does not degrade with growth of file Ê Minimal space overhead Ê Disadvantages of extendable hashing Ê Extra level of indirection to find desired record Ê Bucket address table may itself become very big (larger than memory) Need a tree structure to locate desired record in the structure! Ê Changing size of bucket address table is an expensive operation Ê Linear hashing is an alternative mechanism which avoids these disadvantages at the possible cost of more bucket overflows Comparison of Ordered Indexing and Hashing Ê Cost of periodic re-organization Ê Relative frequency of insertions and deletions Ê Is it desirable to optimize average access time at the expense of worst-case access time? Ê Expected type of queries: Ê Hashing is generally better at retrieving records having a specified value of the key. Ê If range queries are common, ordered indices are to be preferred 34
Grid Files Ê Structure used to speed the processing of general multiple search-key queries involving one or more comparison operators. Ê The grid file has a single grid array and one linear scale for each search-key attribute. The grid array has number of dimensions equal to number of search-key attributes. Ê Multiple cells of grid array can point to same bucket Example: Grid File for account To find the bucket for a search-key value, locate the row and column of its 35
Grid Files Queries on a Grid File Ê grid file on two attributes A and B can handle queries of all following forms with reasonable efficiency E. g. , to answer (a 1 A a 2 b 1 B b 2), - (a 1 A a 2) use linear scales to find corresponding - (b 1 B b 2) candidate grid array cells, and look up - (a 1 A a 2 b 1 B b 2) all the buckets pointed to from those cells. Ê During insertion, if a bucket becomes full, new bucket can be created if more than one cell points to it. Ê Idea similar to extendable hashing, but on multiple dimensions Ê If only one cell points to it, either an overflow bucket must be created or the grid size must be increased Ê Linear scales must be chosen to uniformly distribute records across cells. Otherwise there will be too many overflow buckets. Ê Periodic re-organization to increase grid size will help. But reorganization can be very expensive. Ê Space overhead of grid array can be high. Ê R-trees are an alternative 36
Bitmap Indices Ê Bitmap indices are a special type of index designed for efficient querying on multiple keys Ê Records in a relation are assumed to be numbered sequentially from, say, 0 Given a number n it must be easy to retrieve record n - Particularly easy if records are of fixed size Ê Applicable on attributes that take on a relatively small number of distinct values Ê E. g. gender, country, state, … Ê E. g. income-level (income broken up into a small number of levels such as 09999, 10000 -19999, 20000 -50000, 50000 - infinity) ü Ê In its simplest forman a bitmap A bitmap is simply array ofindex bits on an attribute has a bitmap for each value of the attribute ü Bitmap has as many bits as records ü In a bitmap for value v, the bit for a record is 1 if the record has the 37
Bitmap Indices Ê Bitmap indices are useful for queries on multiple attributes E. g. 100110 AND 110011 = not particularly useful for single attribute queries 100010, Ê Queries are answered using bitmap operations: 100110 OR 110011 = Intersection (and), Union (or), Complementation (not) 110111 NOT 100110 = 011001 Ê Each operation takes two bitmaps of the same size and applies the operation on corresponding bits to get the result bitmap Ê Males with income level L 1: 10010 AND 10100 = 10000 Ê Can then retrieve required tuples. Ê Counting number of matching tuples is even faster Ê Bitmap indices generally very small compared with relation size Ê E. g. if record is 100 bytes, space for a single bitmap is 1/800 of space used by relation. Ê If number of distinct attribute values is 8, bitmap is only 1% of relation size Ê Deletion needs to be handled properly Ê Existence bitmap to note if there is a valid record at a record location Ê Needed for complementation not(A=v): (NOT bitmap-A-v) AND Existence. Bitmap Ê Should keep bitmaps for all values, even null value To correctly handle SQL null semantics for NOT(A=v): intersect above result with (NOT bitmap -A-Null) 38
Bitmap Indices Efficient Implementation of Bitmap Operations Ê Bitmaps are packed into words; a single word and (a basic CPU instruction) computes and of 32 or 64 bits at once E. g. 1 -million-bit maps can be and-ed with just 31, 250 instruction Ê Counting number of 1 s can be done fast by a trick: Ê Use each byte to index into a precomputed array of 256 elements each storing the count of 1 s in the binary representation Ê Can use pairs of bytes to speed up further at a higher memory cost Ê Add up the retrieved counts Ê Bitmaps can be used instead of Tuple-ID lists at leaf levels of B+-trees, for values that have a large number of matching records Ê Worthwhile if > 1/64 of the records have that value, assuming a tuple 39
Index Definition in SQL Create an index: <index-name> [ASC / DESC], . . . ) CREATE [UNIQUE] INDEX ON <relation-name> ( Nom-de-attribut Most database systems allow specification of type of index, and clustering. E. g. Consider the following school database: Student (sid, sname, address, telephone, …) Course (cid, cname, nbhours, coef, #teacher, …) Teacher(tid, tname, …) Student. Course(#sid, #cid, note) Create unique clustered index Std_IXPK ON Student (sid ASC) Create index Course. Teacher_IXFK ON Course (teacher ASC) Indices on Multiple Attributes Create unique clustered index Std. Course_IXPK ON Student. Course (sid ASC, cid ASC) Use create unique index to indirectly specify and enforce the condition that the search key is a candidate key. Use clustered keyword to indicate that the index is a cluster (primary) index 40
- Slides: 40