COMP3311 Week 10 Monday Lecture

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [0/43]
❖ Week 10 Monday

In today's lecture ...

Things to do ...

Coming Up ...

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [1/43]
❖ Assignment 2

How to allocate courses to requirements:

Make a single pass through the courses in the transcript; allocate greedily
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [2/43]
❖ Assignment 2 (cont)

Side-effects of this one-pass greedy allocation approach

First problem could be alleviated by changing the allocation to free Second problem is difficult to fix DO NOT implement these fixes for the assignment
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [3/43]
❖ Transactions (recap)

Transaction are application atomic operations, involing multiple DB ops

A transaction must always terminate, either:

[Diagram:Pics/xact/tx-states1.png]

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [4/43]
❖ Concurrency Control in SQL


Transactions in SQL are specified by

In PostgreSQL, some actions cause implicit rollback: PostgreSQL also provdes ABORT as a synonym for SQL standard ROLLBACK
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [5/43]
❖ Concurrency Control in SQL (cont)

Concurrent access can be controlled via SQL:

LOCK TABLE  explicitly acquires lock on an entire table.

Some SQL commands implicitly acquire appropriate locks, e.g.

All locks are released at end of transaction
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [6/43]
❖ Locking in PostgreSQL

Some locking in PG is implicit (e.g. changing schema)

Explicit locks are available:

lock table TableName [ in LockMode mode ]

Some possible LockModes:

No UNLOCK ... all locks are released at end of transaction

Row-level locking: lock all selected rows for writing

select * from Table where Condition for update

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [7/43]
❖ Locking in PostgreSQL (cont)

Two examples of lock usage in PostgreSQL:

begin;
lock table films in share mode;
select id into _id_ from films
    where name = 'Star Wars: Episode I - The Phantom Menace';
-- Do rollback if no record was returned
insert into films_user_comments values
    (_id_, 'GREAT! I was waiting for it for so long!');
commit;

begin;
lock table films in share row exclusive mode;
delete from films_user_comments where id in
    (select id from films where rating < 5);
delete from films where rating < 5;
commit;

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [8/43]
❖ Exercise: Locking


Apply appropriate locking in the bank transfer transaction.

create or replace function
   transfer(N integer, Src text, Dest text)
   returns integer
declare
   sID integer; dID integer; avail integer;
begin
   select id,balance into sID,avail
   from   Accounts where name=Src;
...
   return nextval('tx_id_seq');
end;

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [9/43]
❖ Locking and Performance

Locking reduces concurrency lower throughput.

Granularity of locking can impact performance:

+ lock a small item more of database accessible

+ lock a small item quick update quick lock release

- lock small items more locks more lock management

Granularity levels: field, row (tuple), table, whole database

Many DBMSs support multiple lock-granularities.

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [10/43]
❖ Multi-version Concurrency Control

One approach to reducing the requirement for locks is to

This approach is called Multi-Version Concurrency Control.

Differences between MVCC and standard locking models:


PostgreSQL pioneered MVCC as a concurrency control mechanism
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [11/43]
❖ Multi-version Concurrency Control (cont)

PostgreSQL MVCC ...

Access to a tuple requires Periodic vacuum process deletes tuples that Time/space overheads in implementing MVCC
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [12/43]
❖ A Brief History of Databases

Some important moments in the development of Databases ...

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [13/43]
❖ Future of Database

Core "database" goals:

At the moment (and for the last 40 years) RDBMSs dominate ... RDBMSs work well in domains with uniform, structured data.
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [14/43]
❖ Future of Database (cont)

Limitations/pitfalls of RDBMSs:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [15/43]
❖ Future of Database (cont)

How to overcome (some of) these limitations?

Extend the relational model ...

Replace the relational model ... Performance: DBMSs that "tune" themselves ...
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [16/43]
❖ Big Data

Some modern applications have massive data sets (e.g. Google)

Approach to dealing with such data Often this data does not need full relational selection
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [17/43]
❖ Big Data (cont)

Popular computational approach to Big Data: map/reduce

Some Big Data proponents see no future need for SQL/relational ...
Humour: Parody of noSQL fans (strong language warning)
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [18/43]
❖ Object-relational Mapping

Pure OO databases came and went in the 90's  (similarly XML databases)

A compromise:

Programmer works purely with objects; wrapper converts to SQL

Problems:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [19/43]
❖ Information Retrieval

DBMSs generally do precise matching (although like/regexps)

Information retrieval systems do approximate matching.

E.g. documents containing these words (Google, etc.)

Also, introduce notion of "quality" of matching
(e.g. tuple T1 is a better match than tuple T2)

Quality also implies ranking of results.

Much activity in incorporating IR ideas into DBMS context.

Goal: support database exploration better.

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [20/43]
❖ Multimedia Data

Data which does not fit the "tabular model":

Research problems: Solutions to the first problem typically: Sample query: find other songs like this one?
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [21/43]
❖ Uncertainty

Multimedia/IR introduces approximate matching.

In some contexts, we have approximate/uncertain data.

E.g. witness statements in a crime-fighting database

"I think the getaway car was red ... or maybe orange ..."

"I am 75% sure that John carried out the crime"

Work by Jennifer Widom at Stanford on the Trio system

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [22/43]
❖ Stream Management Systems

Makes one addition to the relational model

Applications: news feeds, telecomms, monitoring web usage, ...

RDBMSs: run a variety of queries on (relatively) fixed data

StreamDBs: run fixed queries on changing data (stream)

Approaches:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [23/43]
❖ Graph-based Databases


Use graphs rather than tables as basic data structure tool.

Applications: complex data representation, via "flexible" objects

Implementing graphs in RDBMSs is possible, but often inefficient.

Graph nature of data changes query model considerably.

Research problem: query processing for large graphs

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [24/43]
❖ Dispersed Databases

Characteristics of dispersed databases:

Applications: environmental monitoring devices, "intelligent dust", ...

Research issues:

Less extreme versions of this already exist:
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [25/43]
❖ Main-memory Databases


Disk-based data is slow to access, and page-at-a-time

Non-volatile non-disk storage is becoming larger and cheaper

Research problems:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [26/43]
❖ Other DB Research

Open problems:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [27/43]
❖ Beyond COMP3311

COMP9312 Data Analytics for Graphs

COMP9313 Big Data Management COMP9315 Database Systems Implementation COMP9319 Web Data Compression and Search COMP6714 Information Retrieval and Web Search
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [28/43]
❖ COMP3311 Course Aims

At the end of this course you should be able to:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [29/43]
❖ Syllabus Overview

  1. Data modelling and database design
    • Entity-relationship (ER) design, relational data model
    • Relational theory   (algebra, dependencies, normalisation)
  2. Database application development
    • SQL for querying, data definition and modification   (PostgreSQL's version)
    • extending SQL   Queries, Functions, Aggregates, Triggers
    • PostgreSQL,   psql (an SQL shell),   PLpgSQL (procedural SQL)
    • SQLite,   sqlite3 (an SQL shell)
    • Python3,   Psycopg2,   accessing data programmatically
  3. DBMS theory/technology
    • relational algebra,   functional dependencies,   normalization
    • performance tuning,   catalogues,   access control
    • DBMS architecture,   query processing,   transaction processing
Things in gray will definitely not be examined.
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [30/43]
❖ Assessment Summary


Your final mark/grade will be determined as follows:

quizzes = mark for on-line quizzes   (out of 12)
ass1    = mark for assignment 1      (out of 12)
ass2    = mark for assignment 2      (out of 16)
exam    = mark for final exam        (out of 60)
okExam  = exam >= 25                 (after scaling)
mark    = quizzes + ass1 + ass2 + exam
grade   = HD|DN|CR|PS  if mark >= 50 && okExam
        = FL           if mark <  50 && okExam
        = UF           if !okExam

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [31/43]
❖ Final Exam


Mon 4 Dec,   3-hour exam,   morning and afternoon sessions

Morning: arrive by 10:00am,   Afternoon: arrive by 1:20pm

Exam environment:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [32/43]
❖ Final Exam (cont)

Questions ...

What you have access to ... What you do not have access to
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [33/43]
❖ Final Exam (cont)

When you login (zID/zPass) into the exam environment ...

PostgreSQL server runs on your workstation

Database: will not be huge, will not be overly complex (e.g. < 15 tables)

You do not have access to  VLab or  /localstorage  or  /home/YOU

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [34/43]
❖ Final Exam (cont)

For the prac questions ...

For the theory questions ... General suggestions ...
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [35/43]
❖ Final Exam (cont)





Want to know what are the questions on the exam ... ?
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [36/43]
❖ Final Exam (cont)

Questions are as follows:

  1. an SQL query
  2. another SQL query
  3. a PLpgSQL function
  4. a Python3/Psycopg2 script
  5. another Python3/Psycopg2 script
  6. an analysis/synthesis question
  7. another analysis/synthesis question
  8. etc. etc. etc.
Note that the database for Q1-5 will be available in advance.
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [37/43]
❖ Revision


Sources for revision material:

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [38/43]
❖ Supplementary Exams


Supplementary Exams are only available to people who

If you are awarded a Supp Exam ...
COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [39/43]
❖ Assessment

Assessment is about determining how well you understand the syllabus.

If you can't demonstrate your understanding, you won't pass.

In particular, I don't pass people just because ...

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [40/43]
❖ Assessment (cont)


Of course, assessment isn't a "one-way street" ...

MyExperience evaluations are online (via MyUNSW) NOW

Several evaluations: course, lecturer, tutor

Telling us good things is ok.

Telling us things to improve is very useful.

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [41/43]
❖ Some Thoughts ...


You need to learn for life, not just the exam.

In particular, learn to find answers for yourself.

Typically, no single correct answer. (Solutions range from poor to excellent)

Take pride in your work. (Aim for quality, not just correctness)

VScode and autotest will generally not be available in the workplace

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [42/43]
❖ Finally ...

[Diagram:Pics/misc/thats-all-folks.jpg]

Good Luck with the Exams ... and Life ...

COMP3311 23T3 ♢ Week 10 Monday Lecture ♢ [43/43]


Produced: 13 Nov 2023