COMP9315 Week 01 Monday Lecture

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [0/42]
 
COMP9315 24T1
DBMS Implementation
( Data structures and algorithms inside relational DBMSs )

[Diagram:Pics/intro/pgsql.jpg]

Lecturer:   John Shepherd

Web Site:   http://www.cse.unsw.edu.au/~cs9315/

(If WebCMS unavailable, use http://www.cse.unsw.edu.au/~cs9315/24T1/)

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [1/42]
❖ Lecturer

Name:John Shepherd
Admin:Deputy Head of School (education)
Office:K17-410   (turn right from lift)
Email:cs9315@cse.unsw.edu.au
Consults:still working out the details
Research: e-Learning Technologies (e.g. Webcms)
Information Extraction/Integration
Information Retrieval/Web Search
Multimedia Databases
Query Processing

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [2/42]
❖ Useful Contacts

Email:cs9315@cse.unsw.edu.au

The Nucleus Enrolment problems
Special Consideration Illness, Misadventure
Assignment extension, Supp Exam
Must be documented
Forum Assignment Problems
Email/Help Sessions Detailed assignment Problems

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [3/42]
❖ Course Goals

Introduce you to:

Develop skills in:
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [4/42]
❖ Pre-requisites

We assume that you are already familiar with

If you don't know this material very well, don't take this course.
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [5/42]
❖ Exercise: SQL (revision)

Given the following schema:

Students(sid, name, degree, ...)
e.g. Students(3322111, 'John Smith', 'MEngSc', ...)
Courses(cid, code, term, title, ...)
e.g. Courses(1732, 'COMP9311', '12s1', 'Databases', ...)
Enrolments(sid, cid, mark, grade)
e.g. Enrolments(3322111, 1732, 50, 'PS')

Write an SQL query to solve the problem

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [6/42]
❖ Exercise: Unix File I/O (revision)

Write a C program that reads a file, block-by-block.

Command-line parameters:

Use low-level C operations: open, read.

Count and display how many blocks/bytes read.

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [7/42]
❖ Learning/Teaching

What's available for you:

The onus is on you to use this material.


Note: Exercises and videos will be available only after the lecture.

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [8/42]
❖ Learning/Teaching (cont)

Things that you need to do:

Dependencies: There are no tute/lab classes; use Forum, Email, Help Sessions
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [9/42]
❖ Rough Schedule

Week 01intro, dbms review, RA, catalogs
Week 02storage: disks, buffers, pages, tuples
Week 03RA ops: scan, sort, projection
Week 04selection: heaps, hashing, indexes
Week 05selection: N-d matching, similarity
Week 06no lectures
Week 07joins: naive, sort-merge, hash join
Week 08query processing, optimisation
Week 09transactions: concurrency, recovery
Week 10distributed and non-SQL databases

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [10/42]
❖ Textbooks

No official text book; several are suitable ...

but not all cover all topics in detail
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [11/42]
❖ Prac Work

In this course, we use PostgreSQL v15.6   (compulsory)

Prac Work requires you to compile PostgreSQL from source code

Make sure you do the first Prac Exercise when it becomes available.

Sort out any problems ASAP (preferably at a help session).

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [12/42]
❖ Prac Work (cont)

PostgreSQL is a large software system:

You won't be required to understand all of it :-)

You will need to learn to navigate this code effectively.

Will discuss relevant parts in lectures to help with this.

PostgreSQL books?

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [13/42]
❖ Assignments

Schedule of assignment work:

AssDescriptionDueMarks
1New Data TypeWeek 515%
2Query ProcessingWeek 1020%

Assignments will be carried out individually

Ultimately, submission is via CSE's give system.

Will spend some time in lectures reviewing assignments.

Assignments will require up-front code-reading (see Pracs).

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [14/42]
❖ Assignments (cont)

Don't leave assignments to the last minute

Standard UNSW late penalty applies to assignments Valid special consideration can give extension of X days
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [15/42]
❖ Assignments (cont)


Cheating will be penalised with mark of zero for that assignment

You are only cheating yourself ... losing an opportunity to learn
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [16/42]
❖ Quizzes

Over the course of the semester ...

Quizzes are primarily a review tool to check progress.

But they contribute 15% of your overall mark for the course.

No extensions on quizzes, since solutions released on following Monday

For valid special consideration on quiz

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [17/42]
❖ Exam

Three-hour exam in the May exam period.

Exam is held in CSE Labs (learn the environment, VLab)

PostgreSQL and C documentation (only) will be available in the exam.

Things that we can't reasonably test in the exam:

Everything else is potentially examinable.

Contains: descriptive questions, analysis, small programming exercises.

Exam contributes 50% of the overall mark for this course.

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [18/42]
❖ Exam (cont)

If you cannot attend the final exam ...

then you will be offered a Supplementary Exam (in O-week of Term 2)

You get one chance at passing the exam

Exam hurdle 20/50 (which is 40%)

You must attend the exam in-person

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [19/42]
❖ Assessment Summary


Your final mark/grade is computed according to the following:

quiz   = mark for on-line quizzes   (out of 15)
ass1   = mark for assignment 1      (out of 15)
ass2   = mark for assignment 2      (out of 20)
exam   = mark for final exam        (out of 50)
okExam = exam > 20/50           (after scaling)

mark   = ass1 + ass2 + quiz + exam
grade  = HD|DN|CR|PS,  if mark ≥ 50 && okExam
       = FL,           if mark < 50 && okExam
       = UF,           if !okExam

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [20/42]
❖ Relational Database Revision

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [21/42]
❖ Relational DBMS Functionality

Relational DBMSs provide a variety of functionalities:

Common feature of all relational DBMSs: relational model, SQL.
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [22/42]
❖ Data Definition

Relational data: relations/tables, tuples, values, types, e.g.


create domain WAMvalue float
   check (value between 0.0 and 100.0);

create table Students (
   id          integer,  -- e.g. 3123456
   familyName  text,     -- e.g. 'Smith'
   givenName   text,     -- e.g. 'John'
   birthDate   date,     -- e.g. '1-Mar-1984'
   wam         WAMvalue, -- e.g. 85.4
   primary key (id)
);

The above adds meta-data to the database.

DBMSs typically store meta-data as special tables (catalog).

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [23/42]
❖ Data Definition (cont)

Input: DDL statement   (e.g. create table)

[Diagram:Pics/intro/ddl-stat.png]

Result: meta-data in catalog is modified

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [24/42]
❖ Data Modification

Critical function of DBMS: changing data

E.g.

insert into Enrolments(student,course,mark)
values (3312345, 5542, 75);

update Enrolments set mark = 77
where  student = 3354321 and course = 5542;

delete Enrolments where student = 3112233;

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [25/42]
❖ Data Modification (cont)

Input: DML statements

[Diagram:Pics/intro/dml-stat.png]

Result: tuples are added, removed or modified

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [26/42]
❖ Query Evaluator

Most common function of relational DBMSs

E.g.

select s.id, c.code, e.mark
from   Students s
       join Enrolments e on s.id = e.student
       join Courses c on e.course = c.id;

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [27/42]
❖ Query Evaluator (cont)

Input: SQL query

[Diagram:Pics/intro/query.png]

Output: table (displayed as text)

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [28/42]
❖ DBMS Architecture

The aim of this course is to

Why should we care?   (apart from passing the exam)

Practical reason:

Educational reason:
COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [29/42]
❖ DBMS Architecture (cont)

Path of a query through a typical DBMS:

[Diagram:Pics/intro/qryeval1.png]

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [30/42]
❖ DBMS Architecture (cont)

[Diagram:Pics/intro/dbmsarch.png]

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [31/42]
❖ DBMS Architecture (cont)

Important factors related to DBMS architecture

Implications: Modern DBMSs interact with storage via the O/S file-system.


** SSDs change things a little, but most high volume bulk storage still on disks

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [32/42]
❖ DBMS Architecture (cont)

Implementation of DBMS operations is complicated by

Require "concurrency-tolerant" data structures.

Transactions/reliability require some form of logging.

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [33/42]
❖ Installing/Using PostgreSQL

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [34/42]
❖ Installing PostgreSQL

PostgreSQL is available via the COMP9315 web site.

Provided as tar-file in ~cs9315/web/24T1/postgresql/

File: postgresql-15.6.tar.bz2 is ~23MB **

Unpacked, source code + binaries is ~210MB **

If using on CSE, do not put it under your home directory

Place it under /localstorage/YOU/ which has 600MB quota

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [35/42]
❖ Before Installing ...

If you have databases from previous DB courses

E.g.

... login to vxdb
... run your old server for the last time ...
$ pg_dump -O -x myFavDB > /localstorage/YOU/myFavDB.dump
... stop your old server for the last time ...
... remove data from your old server ...
$ rm -fr /localstorage/YOU/pgsql
... install and run your new PostgreSQL 15.6 server ...
$ createdb myFavDB
$ psql myFavDB -f /srvr/YOU/myFavDB.dump
... your old database is restored under 15.6 ...

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [36/42]
❖ Installing/Using PostgreSQL

Environment setup for running PostgreSQL in COMP9315:

# Must be "source"d from sh, bash, ksh, ...

export PGDATA=/localstorage/$USER/pgsql/data
export PGHOST=$PGDATA
export LD_LIBRARY_PATH=/localstorage/$USER/pgsql/lib

export PATH=/localstorage/$USER/pgsql/bin:$PATH

alias p0="pg_ctl stop"
alias p1="pg_ctl -l $PGDATA/log start"

Will probably work (with tweaks) on home laptop if Linux or MacOS

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [37/42]
❖ Installing/Using PostgreSQL (cont)

Brief summary of installation:

$ tar xfj ..../postgresql/src.tar.bz2
  # create a directory postgresql-11.3
  # set up environment variables
$ configure --prefix=$PGHOME
$ make
$ make install
$ source your/environment/file
$ initdb
  # set up postgresql configuration ... done once?
$ edit postgresql.conf
$ pg_ctl start -l $PGDATA/log
  # do some work with PostgreSQL databases
$ pg_ctl stop

COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [38/42]
❖ Exercise: Install PostgreSQL


Follow instruction from previous slide (or P01)

  • install a PostgreSQL server
  • run it without setting environment
  • try to use it without running server
  • try to close it while a job is running
  • examine the files/directories under $PGDATA
  • COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [39/42]
    ❖ Using PostgreSQL for Assignments

    If changes don't modify storage structures ...

    $ edit source code
    $ pg_ctl stop
    $ make
    $ make install
    $ pg_ctl start -l $PGDATA/log
      # run tests, analyse results, ...
    $ pg_ctl stop
    

    In this case, existing databases will continue to work ok.

    COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [40/42]
    ❖ Using PostgreSQL for Assignments (cont)

    If changes modify storage structures ...

    $ edit source code
    $ save a copy of postgresql.conf
    $ pg_dump testdb > testdb.dump
    $ pg_ctl stop
    $ make
    $ make install
    $ rm -fr $PGDATA
    $ initdb
    $ restore postgresql.conf
    $ pg_ctl start -l $PGDATA/log
    $ createdb testdb
    $ psql testdb -f testdb.dump
      # run tests and analyse results
    

    Old databases will not work with the new server.

    COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [41/42]
    ❖ Using PostgreSQL for Assignments (cont)

    Troubleshooting ...

    Prac Exercise P01 has useful tips down the bottom
    COMP9315 24T1 ♢ Week 1 Monday Lecture ♢ [42/42]


    Produced: 13 Feb 2024