vault backup: 2024-01-25 14:02:02
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
if [ $# -ne 1 ]; then
|
||||
echo You need to give just one argument
|
||||
elif [ -d "$1" ]; then
|
||||
echo Deleting directory \"$1\"
|
||||
mv "$1" ~/wastebasket/
|
||||
elif [ -f "$1" ]; then
|
||||
echo Deleting file \"$1\"
|
||||
mv "$1" ~/wastebasket/
|
||||
else
|
||||
echo \"$1\" does not exist
|
||||
fi
|
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
if [ $# -ne 1 ]; then
|
||||
echo You need to give just one argument
|
||||
elif [ -e ~/wastebasket/"$1" ]; then
|
||||
echo \"$1\" already exists in wastebasket, so I will not delete
|
||||
elif [ -d "$1" ]; then
|
||||
if [ $(ls -A "$1" | wc -l) -gt 0 ]; then
|
||||
echo Directory \"$1\" is not empty, so I will not delete
|
||||
else
|
||||
echo Deleting directory \"$1\"
|
||||
mv "$1" ~/wastebasket
|
||||
fi
|
||||
elif [ -f "$1" ]; then
|
||||
echo Deleting file \"$1\"
|
||||
mv "$1" ~/wastebasket
|
||||
else
|
||||
echo \"$1\" does not exist
|
||||
fi
|
BIN
Semester 2/Computer Systems Internals & Linux/Week 2/media.zip
Normal file
BIN
Semester 2/Computer Systems Internals & Linux/Week 2/media.zip
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 3.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 MiB |
Binary file not shown.
After Width: | Height: | Size: 435 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.0 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 MiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
num=1;
|
||||
while [ $# -gt 0 ]; do
|
||||
echo argument $num is \"$1\".
|
||||
shift
|
||||
let num++
|
||||
done
|
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
cat ~/.bash_history | while read line; do
|
||||
if echo $line | grep -Eq "^(mkdir|cd)"; then
|
||||
dir=$(echo $line | sed -r 's/(mkdir|cd) +//')
|
||||
if [ -d "$dir" ]; then
|
||||
echo "YES: $dir"
|
||||
else
|
||||
echo "NO: $dir"
|
||||
fi
|
||||
fi
|
||||
done
|
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
file=1;
|
||||
for audio in media/*.mp3; do
|
||||
if [ $audio != "media/footsteps_forest_01.mp3" ]; then
|
||||
echo Processing $audio
|
||||
filename="00$file"
|
||||
filename=${filename:(-3)}
|
||||
sox $audio temp.wav silence 1 0 0
|
||||
sox media/footsteps_forest_01.mp3 temp.wav -C 128 $filename.mp3
|
||||
rm temp.wav
|
||||
let file=file+1
|
||||
fi
|
||||
done
|
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
date=$(date "+%a %d-%m-%Y %H:%M")
|
||||
for image in media/*.jpg; do
|
||||
filename=$(basename $image)
|
||||
if [ -e thumbs/$filename ]; then
|
||||
echo $filename has already been converted
|
||||
else
|
||||
echo Converting $filename
|
||||
convert $image -resize "640x480>" -rotate 90 -background magenta -pointsize 15 -gravity Center label:"$date" -append -rotate -90 thumbs/$filename
|
||||
fi
|
||||
done
|
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
dir=$(dirname "$1")
|
||||
file=$(basename "$1")
|
||||
if [ $# -ne 1 ]; then
|
||||
echo You need to give just one argument
|
||||
elif [ ! -e ~/wastebasket/"$file" ]; then
|
||||
echo \"$file\" does not exist in wastebasket
|
||||
elif [ -e "$1" ]; then
|
||||
echo \"$1\" already exists, so I will not undelete
|
||||
else
|
||||
echo Restoring \"$file\" to \"$dir\"
|
||||
if [ ! -d "$dir" ]; then
|
||||
mkdir "$dir"
|
||||
fi
|
||||
mv ~/wastebasket/"$file" "$dir"
|
||||
fi
|
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
for video in media/*.mp4 media/*.mov; do
|
||||
if [ ! -e $video ]; then
|
||||
echo No videos to convert
|
||||
exit 1
|
||||
fi
|
||||
echo Processing $video
|
||||
dir=$(dirname "$video")
|
||||
file=$(basename "$video" .mp4)
|
||||
file=$(basename "$file" .mov)
|
||||
avconv -i $video -s 80x50 $dir/$file.mpg
|
||||
|
||||
mv $video $video.backup
|
||||
done
|
19772
Semester 2/Database Systems/Exercise Booklet.pdf
Normal file
19772
Semester 2/Database Systems/Exercise Booklet.pdf
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,78 @@
|
||||
# Query Optimisation
|
||||
|
||||
Dominant cost in query processing is secondary storage access. The fewer blocks accessed, the faster the database queries can be.
|
||||
Many tuples will fit into a single block, requiring the query to: find the block, find the tuple, edit the tuple, and place it back in the block. This is inefficient if we are doing many different queries accessing different blocks.
|
||||
|
||||
# Types of Index
|
||||
|
||||
## Primary Index
|
||||
|
||||
Data file sequentially ordered by ordering key field, indexing field is built on the ordering key field. Guaranteed to have unique value for each tuple.
|
||||
|
||||
## Clustering Index
|
||||
|
||||
Data file sequentially ordered on non-key field, indexing field built on same non-key field. Can be more than one tuple corresponding to a value in the indexing field.
|
||||
|
||||
## Primary / Clustered Indices
|
||||
|
||||
Affect the order the data is stored in a file.
|
||||
|
||||
## Secondary Indices
|
||||
|
||||
Give a lookup table to the file.
|
||||
|
||||
# Index Restrictions
|
||||
|
||||
- Table can have 1 primary index OR 1 clustering index.
|
||||
- Most frequently looked up value is often the best choice
|
||||
- Some DBMS' assume PK is primary index, as it is usually used to refer to rows
|
||||
|
||||
# Exercise
|
||||
|
||||
1. What is a Query Tree?
|
||||
A query tree is a visual model used to represent a logical model of database queries. Each leaf node represents a relation. Each internal node is a different query function ex. selection, projection, product, etc.
|
||||
|
||||
2. Write a relational algebra expression for the following query
|
||||
|
||||
```sql
|
||||
SELECT lecName, schedule
|
||||
FROM lecturer, module, enroll, student
|
||||
WHERE lastName=“Burns”
|
||||
AND firstName=“Edward”
|
||||
AND module.moduleNumber=enrol.moduleNumber
|
||||
AND lecturer.lecID=module.lectID
|
||||
AND student.stuID=enrol.stuID;
|
||||
```
|
||||

|
||||
|
||||
pi lecName, schedule
|
||||
( sigma lastName = burns
|
||||
( sigma firstName = edwards
|
||||
( sigma module.moduleNumber=enrol.moduleNumber
|
||||
( sigma (lecturer.ledID=module.lectID (lecturer x module ) x enrol ) x student
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Draw a Query Tree for this SQL query:
|
||||
|
||||
3. Why can we not use SQL for query optimisation?
|
||||
Using relational algebra is easier for us to visualise, and less abstracted than SQL, allowing us to optimise the query flow.
|
||||
|
||||
4. List the heuristics that optimisers use to reduce optimisation cost.
|
||||
- Begin with initial query tree for SQL
|
||||
- Move SELECT operations down the tree
|
||||
- Apply more restrictive SELECT operations first ( eg. equalities before range queries )
|
||||
- Replace Cartesian products followed by selection with theta joins ( eg. *sigma(f) ( RxS )* -> *R theta(f) S* )
|
||||
- Move PROJECT operations down the query tree ( add project operations as inputs to theta joins ).
|
||||
|
||||
5. Draw a near optimal query tree for the following SQL query, and write a relational algebra expression for this tree.
|
||||
```sql
|
||||
SELECT sailors.name
|
||||
FROM sailors, reservations
|
||||
WHERE reservations.sID=sailors.ID
|
||||
AND reservations.bID=100
|
||||
AND sailors.rating=7;
|
||||
```
|
||||
|
||||

|
@@ -0,0 +1 @@
|
||||
#
|
Reference in New Issue
Block a user