0% found this document useful (0 votes)
14 views10 pages

Lecture 5 - Indexes 2 - Template

DBMS NOTES

Uploaded by

myotherface16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

Lecture 5 - Indexes 2 - Template

DBMS NOTES

Uploaded by

myotherface16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lecture 5 – Indexes – Part 2

COMP 519: Advanced Databases

Topics:
Hashing
Spatial Indexing
Indexing in Postgres

Reading:
Chapter 14

Hashing

Static Hashing

Bucket:

Hash function h:

hash index:

Handling of Bucket Overflows

Overflow chaining:
Example of Hash Organization

Note:

Deficiencies of Static Hashing

In static hashing, function h maps search-key values to a fixed set of B of bucket addresses.

Q: Why could this approach be problematic with databases?


Dynamic Hashing

Periodic rehashing

Extendable Hashing

Global Depth:

Local Depth:

Inserting elements: 2, 10, 8, 4, 5, 7, 11, where hash is key % 32, and bucket size is 3.
Multiple-Key Access

select ID
from instructor
where dept_name = “Finance” and salary = 80000

Q: How might we process this query?

Indices on Multiple Keys

Q: Can also an index on (dept_name, salary) efficiently handle the following query?

where dept_name = “Finance” and salary < 80000

Q: Can also an index on (dept_name, salary) efficiently handle the following query?

where dept_name < “Finance” and balance = 80000


Creation of Indices

Index Definition in SQL

create index <index-name> on <relation-name> (<attribute-list>)

Example SQL syntax:

create index takes_pk on takes (ID,course_ID, year, semester, section)

drop index takes_pk

Indices on primary key created automatically by all databases

Some database also create indices on foreign key attributes

Q: Why might such an index be useful for this query:


takes ⨝ σname='Shankar' (student)

Q: Why not index every field?


Spatial Indices

k-d tree
Quadtrees
Postgres Create Index Command:

CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON


table_name [ USING method ] ( { column_name | ( expression ) }
[ COLLATE collation ]
[ opclass [ ( opclass_parameter = value [, ... ] ) ] ]
[ ASC | DESC ] [ NULLS { FIRST | LAST } ]
[ WITH ( storage_parameter [= value] [, ... ] ) ]

Methods:

B-Tree:

Q: The documentation states that some queries involving the pattern matching operators LIKE can be
used. Which one of these would likely be supported?
col LIKE 'foo%'
col LIKE '%bar'

Hash: a 32-bit hash code derived from the value of the indexed column. Can only be a single column.

Q: Which operators from above are supported?

GiST:

SP-GiST:

BRIN:
Index Storage Parameters

fillfactor (integer)

deduplicate_items (boolean)

Clustering Indices in Postgres

CLUSTER [VERBOSE] table_name [ USING index_name ]

You might also like