├── lab_4
├── extmem-c
│ ├── 31415926.blk
│ ├── .DS_Store
│ ├── bin
│ │ ├── .DS_Store
│ │ └── Debug
│ │ │ └── extmem.exe
│ ├── extmem.depend
│ ├── obj
│ │ ├── .DS_Store
│ │ └── Debug
│ │ │ ├── extmem.o
│ │ │ ├── main.o
│ │ │ └── test.o
│ ├── extmem.layout
│ ├── extmem.cbp
│ ├── test.c
│ ├── extmem.h
│ └── extmem.c
├── 实验四.pdf
├── .DS_Store
├── README.md
└── lab_4
│ ├── CMakeLists.txt
│ ├── random_data.h
│ ├── random_data.c
│ ├── test.c
│ ├── extmem.h
│ ├── README.md
│ └── extmem.c
├── lab_3
├── DreamHome_Ref_Data
│ ├── Client.bad
│ ├── Viewing.bad
│ ├── Registration.dat
│ ├── Branch.ctl
│ ├── Viewing.ctl
│ ├── Client.ctl
│ ├── PrivateOwner.ctl
│ ├── Staff.ctl
│ ├── Registration.ctl
│ ├── Viewing.dat
│ ├── Client.dat
│ ├── Branch.dat
│ ├── PropertyForRent.ctl
│ ├── PrivateOwner.dat
│ ├── Staff.dat
│ ├── PropertyForRent.dat
│ └── PropertyForRent.bad
├── DreamHome_Data
│ ├── Manager.txt
│ ├── Owner.txt
│ ├── Lease.txt
│ ├── Advertisement.txt
│ ├── Newpaper.txt
│ ├── BusinessOwner.txt
│ ├── Viewing.txt
│ ├── Client.txt
│ ├── Branch_Tel.txt
│ ├── Branch.txt
│ ├── PrivateOwner.txt
│ ├── Staff.txt
│ └── PropertyForRent.txt
├── 实验三.pdf
├── DreamHome_ER.pdf
├── dreamhome_ref.pdf
├── dreamhome_data.pdf
├── dreamhome-database.pdf
├── lab_3
│ ├── README.md
│ └── src
│ │ └── sample
│ │ └── Main.java
└── DreamHome_ER.tex
├── lab_1
├── 实验一.pdf
├── report
│ ├── doc.pdf
│ ├── media
│ │ ├── 3.1.1.png
│ │ ├── 3.1.2.png
│ │ ├── 3.1.3.png
│ │ ├── 3.1.4.png
│ │ ├── 3.1.5.png
│ │ ├── 3.1.6.png
│ │ ├── 3.1.7.png
│ │ ├── 3.1.8.png
│ │ ├── 3.1.9.png
│ │ ├── 3.2.1.png
│ │ ├── 3.2.2.png
│ │ ├── 3.2.3.png
│ │ ├── 3.2.4.png
│ │ ├── 3.3.1.png
│ │ ├── 3.3.2.png
│ │ ├── 3.3.3.png
│ │ ├── 3.3.4.png
│ │ ├── HIT.jpeg
│ │ └── 3.1.3-2.png
│ ├── BaseSetting.cls
│ ├── ml.cls
│ └── doc.tex
├── 数据库系统_实验报告1模板_2019年春季学期.pdf
├── lab_1
│ ├── source_file
│ │ ├── employee_location.txt
│ │ ├── department_name.txt
│ │ ├── project_name_location.txt
│ │ ├── projects.txt
│ │ ├── departments.txt
│ │ ├── employee_id.txt
│ │ ├── employees.txt
│ │ └── work_on.txt
│ └── src
│ │ └── Main.java
└── pet.txt
├── lab_2
├── doc.pdf
├── 实验二.pdf
├── media
│ └── HIT.jpeg
├── 数据库系统_实验报告2模板_2019年春季学期.pdf
├── BaseSetting.cls
├── ml.cls
├── lab_2
│ └── src
│ │ ├── Main.java
│ │ └── COMPANY_Query.java
└── doc.tex
├── homework_1
├── 第一次作业.pdf
├── 第一次作业反馈.pdf
├── homewoke_1.pdf
└── homewoke_1.tex
├── homework_2
├── 第二次作业.pdf
├── 第二次作业反馈.pdf
├── homework_2.pdf
└── homework_2.tex
├── homework_3
├── 作业3反馈.pdf
├── 第三次作业.pdf
├── homework_3.pdf
└── homework_3.tex
├── homework_4
├── 作业4反馈.pdf
├── 第四次作业.pdf
├── homework_4.pdf
├── LosslessJoinExample.pdf
├── Decomposition into BCNF.pdf
└── homework_4.tex
├── homework_5
├── 第五次作业.pdf
├── 第五次作业反馈.pdf
└── 第五次作业-1160300314-朱明彦.pdf
├── homework_6
├── 第六次作业.pdf
├── 第六次作业反馈.pdf
├── homework_6.pdf
└── homework_6.tex
├── Paper_Summary
├── doc.pdf
├── media
│ ├── HIT.jpeg
│ ├── IER.png
│ ├── ROAD.png
│ ├── DisBrw.png
│ ├── delete.png
│ ├── g-tree.png
│ ├── insert.png
│ ├── query.png
│ ├── v-tree.png
│ ├── downhill.png
│ ├── example-1.jpg
│ ├── example-2.jpg
│ ├── notations.png
│ ├── cover_nodes.png
│ └── compute_rank.png
├── BaseSetting.cls
├── ml.cls
└── doc.tex
├── lab_report_template
├── doc.pdf
├── media
│ └── HIT.jpeg
├── doc.tex
├── BaseSetting.cls
└── ml.cls
├── Prof. Zhaonian Zou
├── assignment1.pdf
├── assignment2.pdf
├── assignment3.pdf
├── assignment4.pdf
├── assignment1_anwers.pdf
├── assignment2_answers.pdf
├── assignment3_answers.pdf
└── assignment4_answers.pdf
├── README.md
├── template.tex
└── .gitignore
/lab_4/extmem-c/31415926.blk:
--------------------------------------------------------------------------------
1 | abcdefgh
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Client.bad:
--------------------------------------------------------------------------------
1 | CR74,Mike,Ritchie,House,750
2 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Manager.txt:
--------------------------------------------------------------------------------
1 | SL21,B005,30000,2015-06
2 | SG5,B003,24000,2018-12
3 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Owner.txt:
--------------------------------------------------------------------------------
1 | C101
2 | C102
3 | CO46
4 | CO87
5 | CO40
6 | CO93
7 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Viewing.bad:
--------------------------------------------------------------------------------
1 | CR56,PG4,26-May-95,
2 | CR56,PG36,28-Apr-95,
3 |
--------------------------------------------------------------------------------
/lab_1/实验一.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/实验一.pdf
--------------------------------------------------------------------------------
/lab_2/doc.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_2/doc.pdf
--------------------------------------------------------------------------------
/lab_2/实验二.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_2/实验二.pdf
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Lease.txt:
--------------------------------------------------------------------------------
1 | R11,CR74,PA14,650,1300,Y,Wechat,12,2018-04-01,2019-04-01
2 |
--------------------------------------------------------------------------------
/lab_3/实验三.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_3/实验三.pdf
--------------------------------------------------------------------------------
/lab_4/实验四.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/实验四.pdf
--------------------------------------------------------------------------------
/lab_4/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/.DS_Store
--------------------------------------------------------------------------------
/lab_4/README.md:
--------------------------------------------------------------------------------
1 | # Lab 4
2 | - `extmem-c`为实验所提供的库文件。
3 | - `lab_4`为本次实验的主要文件。
4 | - `实验四.pdf`为本次实验的指导书。
--------------------------------------------------------------------------------
/homework_1/第一次作业.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_1/第一次作业.pdf
--------------------------------------------------------------------------------
/homework_2/第二次作业.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_2/第二次作业.pdf
--------------------------------------------------------------------------------
/homework_3/作业3反馈.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_3/作业3反馈.pdf
--------------------------------------------------------------------------------
/homework_3/第三次作业.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_3/第三次作业.pdf
--------------------------------------------------------------------------------
/homework_4/作业4反馈.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_4/作业4反馈.pdf
--------------------------------------------------------------------------------
/homework_4/第四次作业.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_4/第四次作业.pdf
--------------------------------------------------------------------------------
/homework_5/第五次作业.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_5/第五次作业.pdf
--------------------------------------------------------------------------------
/homework_6/第六次作业.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_6/第六次作业.pdf
--------------------------------------------------------------------------------
/lab_1/report/doc.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/doc.pdf
--------------------------------------------------------------------------------
/lab_2/media/HIT.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_2/media/HIT.jpeg
--------------------------------------------------------------------------------
/Paper_Summary/doc.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/doc.pdf
--------------------------------------------------------------------------------
/homework_1/第一次作业反馈.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_1/第一次作业反馈.pdf
--------------------------------------------------------------------------------
/homework_2/第二次作业反馈.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_2/第二次作业反馈.pdf
--------------------------------------------------------------------------------
/homework_5/第五次作业反馈.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_5/第五次作业反馈.pdf
--------------------------------------------------------------------------------
/homework_6/第六次作业反馈.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_6/第六次作业反馈.pdf
--------------------------------------------------------------------------------
/lab_3/DreamHome_ER.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_3/DreamHome_ER.pdf
--------------------------------------------------------------------------------
/lab_3/dreamhome_ref.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_3/dreamhome_ref.pdf
--------------------------------------------------------------------------------
/homework_1/homewoke_1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_1/homewoke_1.pdf
--------------------------------------------------------------------------------
/homework_2/homework_2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_2/homework_2.pdf
--------------------------------------------------------------------------------
/homework_3/homework_3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_3/homework_3.pdf
--------------------------------------------------------------------------------
/homework_4/homework_4.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_4/homework_4.pdf
--------------------------------------------------------------------------------
/homework_6/homework_6.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_6/homework_6.pdf
--------------------------------------------------------------------------------
/lab_3/dreamhome_data.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_3/dreamhome_data.pdf
--------------------------------------------------------------------------------
/lab_4/extmem-c/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/.DS_Store
--------------------------------------------------------------------------------
/Paper_Summary/media/HIT.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/HIT.jpeg
--------------------------------------------------------------------------------
/Paper_Summary/media/IER.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/IER.png
--------------------------------------------------------------------------------
/Paper_Summary/media/ROAD.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/ROAD.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.1.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.2.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.3.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.4.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.5.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.6.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.7.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.8.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.9.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.2.1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.2.1.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.2.2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.2.2.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.2.3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.2.3.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.2.4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.2.4.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.3.1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.3.1.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.3.2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.3.2.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.3.3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.3.3.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.3.4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.3.4.png
--------------------------------------------------------------------------------
/lab_1/report/media/HIT.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/HIT.jpeg
--------------------------------------------------------------------------------
/lab_3/dreamhome-database.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_3/dreamhome-database.pdf
--------------------------------------------------------------------------------
/lab_4/extmem-c/bin/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/bin/.DS_Store
--------------------------------------------------------------------------------
/lab_4/extmem-c/extmem.depend:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/extmem.depend
--------------------------------------------------------------------------------
/lab_4/extmem-c/obj/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/obj/.DS_Store
--------------------------------------------------------------------------------
/lab_report_template/doc.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_report_template/doc.pdf
--------------------------------------------------------------------------------
/Paper_Summary/media/DisBrw.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/DisBrw.png
--------------------------------------------------------------------------------
/Paper_Summary/media/delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/delete.png
--------------------------------------------------------------------------------
/Paper_Summary/media/g-tree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/g-tree.png
--------------------------------------------------------------------------------
/Paper_Summary/media/insert.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/insert.png
--------------------------------------------------------------------------------
/Paper_Summary/media/query.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/query.png
--------------------------------------------------------------------------------
/Paper_Summary/media/v-tree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/v-tree.png
--------------------------------------------------------------------------------
/lab_1/report/media/3.1.3-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/report/media/3.1.3-2.png
--------------------------------------------------------------------------------
/Paper_Summary/media/downhill.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/downhill.png
--------------------------------------------------------------------------------
/Paper_Summary/media/example-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/example-1.jpg
--------------------------------------------------------------------------------
/Paper_Summary/media/example-2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/example-2.jpg
--------------------------------------------------------------------------------
/Paper_Summary/media/notations.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/notations.png
--------------------------------------------------------------------------------
/lab_1/数据库系统_实验报告1模板_2019年春季学期.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_1/数据库系统_实验报告1模板_2019年春季学期.pdf
--------------------------------------------------------------------------------
/lab_2/数据库系统_实验报告2模板_2019年春季学期.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_2/数据库系统_实验报告2模板_2019年春季学期.pdf
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Advertisement.txt:
--------------------------------------------------------------------------------
1 | People,2018-04-08,PA14,100
2 | People,2018-04-08,PL94,100
3 | China Daily,2018-04-05,PA14,200
--------------------------------------------------------------------------------
/lab_4/extmem-c/obj/Debug/extmem.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/obj/Debug/extmem.o
--------------------------------------------------------------------------------
/lab_4/extmem-c/obj/Debug/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/obj/Debug/main.o
--------------------------------------------------------------------------------
/lab_4/extmem-c/obj/Debug/test.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/obj/Debug/test.o
--------------------------------------------------------------------------------
/Paper_Summary/media/cover_nodes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/cover_nodes.png
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment1.pdf
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment2.pdf
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment3.pdf
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment4.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment4.pdf
--------------------------------------------------------------------------------
/homework_4/LosslessJoinExample.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_4/LosslessJoinExample.pdf
--------------------------------------------------------------------------------
/homework_5/第五次作业-1160300314-朱明彦.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_5/第五次作业-1160300314-朱明彦.pdf
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Newpaper.txt:
--------------------------------------------------------------------------------
1 | China Daily,0086-(0)10-84883603,Haidian Beijing,Miss Zhang
2 | People,010-65368759,Zhong Nan Hai,Sir Liu
--------------------------------------------------------------------------------
/lab_4/extmem-c/bin/Debug/extmem.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_4/extmem-c/bin/Debug/extmem.exe
--------------------------------------------------------------------------------
/lab_report_template/media/HIT.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/lab_report_template/media/HIT.jpeg
--------------------------------------------------------------------------------
/Paper_Summary/media/compute_rank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Paper_Summary/media/compute_rank.png
--------------------------------------------------------------------------------
/homework_4/Decomposition into BCNF.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/homework_4/Decomposition into BCNF.pdf
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment1_anwers.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment1_anwers.pdf
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment2_answers.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment2_answers.pdf
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment3_answers.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment3_answers.pdf
--------------------------------------------------------------------------------
/Prof. Zhaonian Zou/assignment4_answers.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MingyanZHU/DataBase_2019_Spring/HEAD/Prof. Zhaonian Zou/assignment4_answers.pdf
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Registration.dat:
--------------------------------------------------------------------------------
1 | CR76,B005,SL41,2-Jan-01
2 | CR56,B003,SG37,11-Apr-00
3 | CR74,B003,SG37,16-Nov-99
4 | CR62,B007,SA9,7-Mar-00
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Branch.ctl:
--------------------------------------------------------------------------------
1 | LOAD DATA
2 | INFILE Branch.dat
3 | APPEND INTO TABLE branch
4 | FIELDS TERMINATED BY ','
5 | (branchno,street,city,postcode)
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/BusinessOwner.txt:
--------------------------------------------------------------------------------
1 | C101,HUAWEI,Shenzhen Guangdong,400-830-8300,Technology,Zhengfei Ren
2 | C102,Alibaba,Hangzhou Zhejiang,400-860-8608,EBuy,Jack Ma
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Viewing.ctl:
--------------------------------------------------------------------------------
1 | LOAD DATA
2 | INFILE Viewing.dat
3 | APPEND INTO TABLE viewing
4 | FIELDS TERMINATED BY ','
5 | (clientno,propertyno,viewdate,commnt)
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Client.ctl:
--------------------------------------------------------------------------------
1 | LOAD DATA
2 | INFILE Client.dat
3 | APPEND INTO TABLE client
4 | FIELDS TERMINATED BY ','
5 | (clientno,fname,lname,telno,preftype,maxrent)
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/PrivateOwner.ctl:
--------------------------------------------------------------------------------
1 | LOAD DATA
2 | INFILE PrivateOwner.dat
3 | APPEND INTO TABLE Privateowner
4 | FIELDS TERMINATED BY ','
5 | (ownerno,fname,lname,address,telno)
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Staff.ctl:
--------------------------------------------------------------------------------
1 | LOAD DATA
2 | INFILE Staff.dat
3 | APPEND INTO TABLE staff
4 | FIELDS TERMINATED BY ','
5 | (staffno,fname,lname,position,sex,dob,salary,branchno)
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Registration.ctl:
--------------------------------------------------------------------------------
1 | LOAD DATA
2 | INFILE Registration.dat
3 | APPEND INTO TABLE registration
4 | FIELDS TERMINATED BY ','
5 | (clientno,branchno,staffno,datejoined)
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Viewing.dat:
--------------------------------------------------------------------------------
1 | CR56,PA14,24-May-95,too small
2 | CR76,PG4,20-Apr-95,too remote
3 | CR56,PG4,26-May-95,
4 | CR62,PA14,14-May-95,no dining room
5 | CR56,PG36,28-Apr-95,
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Viewing.txt:
--------------------------------------------------------------------------------
1 | CR56,PA14,2018-05-24,too small
2 | CR76,PG4,2018-04-20,too remote
3 | CR56,PG4,2018-04-26,
4 | CR62,PA14,2017-05-24,no dining room
5 | CR56,PG36,2018-04-28,
6 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Client.dat:
--------------------------------------------------------------------------------
1 | CR76,John,Kay,0171-774-5632,Flat,425
2 | CR56,Aline,Steward,0141-848-1825,Flat,350
3 | CR74,Mike,Ritchie,House,750
4 | CR62,Mary,Tregear,01224-196720,Flat,600
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Client.txt:
--------------------------------------------------------------------------------
1 | CR76,John Kay,0171-774-5632,Flat,425
2 | CR56,Aline Steward,0141-848-1825,Flat,350
3 | CR74,Mike Ritchie,18846082306,House,750
4 | CR62,Mary Tregear,01224-196720,Flat,600
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Branch_Tel.txt:
--------------------------------------------------------------------------------
1 | B005,045186412114
2 | B007,045186417802
3 | B003,045186414671
4 | B003,045186414888
5 | B004,045186414771
6 | B002,045186414717
7 | B002,045186414666
8 | B002,045186414000
9 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Branch.txt:
--------------------------------------------------------------------------------
1 | B005,22 Deer Rd,London,SW1 4EH
2 | B007,16 Argyll St,Aberdeen,AB2 3SU
3 | B003,163 Main St,Glasgow,G11 9QX
4 | B004,32 Manse Rd,Bristol,BS99 1NZ
5 | B002,56 Clover Dr,London,NW10 6EU
6 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Branch.dat:
--------------------------------------------------------------------------------
1 | B005,22 Deer Rd,London,SW1 4EH
2 | B007,16 Argyll St,Aberdeen,AB2 3SU
3 | B003,163 Main St,Glasgow,G11 9QX
4 | B004,32 Manse Rd,Bristol,BS99 1NZ
5 | B002,56 Clover Dr,London,NW10 6EU
6 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/PropertyForRent.ctl:
--------------------------------------------------------------------------------
1 | LOAD DATA
2 | INFILE PropertyForRent.dat
3 | APPEND INTO TABLE propertyforrent
4 | FIELDS TERMINATED BY ','
5 | (propertyno,street,city,postcode,type,rooms,rent,ownerno,staffno,branchno)
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/employee_location.txt:
--------------------------------------------------------------------------------
1 | 南岗区北京街100号
2 | 哈尔滨市南岗区松花江街139号
3 | 哈尔滨市道里区抚利街与抚顺街交会处
4 | 大民兴街9号
5 | 红领巾街02-2号
6 | 黑龙江省哈尔滨市南岗区和兴十一道街28-1号
7 | 哈尔滨市道里区顾新路295号
8 | 哈尔滨市道里区河松街219号
9 | 黑龙江省哈尔滨市道里区安阳路1号
10 | 顾新路396号
11 | 哈尔滨市南岗区学府三道街27号
--------------------------------------------------------------------------------
/lab_4/lab_4/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 | project(lab_4 C)
3 |
4 | set(CMAKE_C_STANDARD 11)
5 |
6 | include_directories(.)
7 |
8 | add_executable(lab_4
9 | extmem.c extmem.h lab4.c random_data.c random_data.h)
10 |
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/department_name.txt:
--------------------------------------------------------------------------------
1 | Research Department
2 | Design Department
3 | Technology Department
4 | International Department
5 | Management Department
6 | Personal Department
7 | Business Department
8 | Sale Department
9 | Publicity Department
10 |
--------------------------------------------------------------------------------
/lab_1/pet.txt:
--------------------------------------------------------------------------------
1 | Fluffy Harold cat f 1993-02-04 \n
2 | Claws Gwen cat m 1994-03-17 \n
3 | Buffy Harold dog f 1989-05-13 \n
4 | Fang Benny dog m 1990-08-27 \n
5 | Chirpy Gwen bird f 1998-09-11 \n
6 | Whistler Gwen bird f 1997-12-09 \n
7 | Slim Benny snake m 1996-04-29 \n
8 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/PrivateOwner.txt:
--------------------------------------------------------------------------------
1 | CO46,Joe Keogh,2 Fergus Dr. Aberdeen AB2 7SX,01224-861212
2 | CO87,Carol Farrel,6 Achray St. Glasgow G32 9DX,0141-357-7419
3 | CO40,Tina Murphy,63 Well St. Glasgow G42,0141-943-1728
4 | CO93,Tony Shaw,12 Park Pl. Glasgow G4 0QR,0141-225-7025
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/PrivateOwner.dat:
--------------------------------------------------------------------------------
1 | CO46,Joe,Keogh,2 Fergus Dr. Aberdeen AB2 7SX,01224-861212
2 | CO87,Carol,Farrel,6 Achray St. Glasgow G32 9DX,0141-357-7419
3 | CO40,Tina,Murphy,63 Well St. Glasgow G42,0141-943-1728
4 | CO93,Tony,Shaw,12 Park Pl. Glasgow G4 0QR,0141-225-7025
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/Staff.txt:
--------------------------------------------------------------------------------
1 | SL21,John White,Manager,M,,300000,B005
2 | SG37,Ann Beech,Assistant,F,SG5,12000,B003
3 | SG14,David Ford,Assistant,M,SG5,18000,B003
4 | SA9,Mary Howe,Assistant,F,,9000,B007
5 | SG5,Susan Brand,Manager,F,,24000,B003
6 | SL41,Julie Lee,Assistant,F,SL21,9000,B005
7 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/Staff.dat:
--------------------------------------------------------------------------------
1 | SL21,John White,Manager,M,,300000,B005
2 | SG37,Ann Beech,Assistant,F,SG5,12000,B003
3 | SG14,David Ford,Assistant,M,SG5,18000,B003
4 | SA9,Mary Howe,Assistant,F,9000,,B007
5 | SG5,Susan Brand,Manager,F,24000,,B003
6 | SL41,Julie Lee,Assistant,F,9000,SL21,B005
7 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_Data/PropertyForRent.txt:
--------------------------------------------------------------------------------
1 | PA14,16 Holhead,Aberdeen,AB7 5SU,House,6,650,CO46,SA9
2 | PL94,6 Argyll St,London,NW2,Flat,4,400,CO87,SL41
3 | PG4,6 Lawrence St,Glasgow,G11 9QX,Flat,3,350,C101,SG5
4 | PG36,2 Manor Rd,Glasgow,G32 4QX,Flat,3,375,CO93,SG37
5 | PG21,18 Dale Rd,Glasgow,G12,House,5,600,CO87,SG37
6 | PG16,5 Novar Dr,Glasgow,G12 9AX,Flat,4,450,CO93,SG14
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/project_name_location.txt:
--------------------------------------------------------------------------------
1 | CPP_Project 香安电力小区
2 | JAVA_Project 哈高新区科技创新园核心区规划291路以西
3 | SQL_Project 西钢大厦及西钢嘉苑小区
4 | 丽水丁香园小区既有物业服务 哈尔滨市道里区工农街道办事处
5 | 哈尔滨开发-化工区集中供热扩建项目 哈尔滨市香坊区化工路103号哈投股份热电厂-分厂院内
6 | 翠湖天地小区-翠园既有物业服务项目 哈尔滨市道里区丽江路2842号
7 | 林海华庭小区物业服务 林海华庭小区
8 | 哈尔滨市南岗区中发郦苑小区既有物业服务项目 哈尔滨市南岗区先锋路591号
9 | 松北国际家居生活广场三期 松北国际家居生活广场
10 | 中海文昌公馆项目 南岗区文景街和文景头道街交口
11 | 珑瑞小区项目既有物业服务 香坊区香大办事处通站社区
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/PropertyForRent.dat:
--------------------------------------------------------------------------------
1 | PA14,16 Holhead,Aberdeen,AB7 5SU,House,6,650,CO46,SA9,B007
2 | PL94,6 Argyll St,London,NW2,Flat,4,400,CO87,SL41,B005
3 | PG4,6 Lawrence St,Glasgow,G11 9QX,Flat,3,350,CO40,,B003
4 | PG36,2 Manor Rd,Glasgow,G32 4QX,Flat,3,375,CO93,SG37,B003
5 | PG21,18 Dale Rd,Glasgow,G12,House,5,600,CO87,SG37,B003
6 | PG16,5 Novar Dr,Glasgow,G12 9AX,Flat,4,450,CO93,SG14,B003
--------------------------------------------------------------------------------
/lab_3/DreamHome_Ref_Data/PropertyForRent.bad:
--------------------------------------------------------------------------------
1 | PA14,16 Holhead,Aberdeen,AB7 5SU,House,6,650,CO46,SA9,B007
2 | PL94,6 Argyll St,London,NW2,Flat,4,400,CO87,SL41,B005
3 | PG4,6 Lawrence St,Glasgow,G11 9QX,Flat,3,350,CO40,NULL,B003
4 | PG36,2 Manor Rd,Glasgow,G32 4QX,Flat,3,375,CO93,SG37,B003
5 | PG21,18 Dale Rd,Glasgow,G12,House,5,600,CO87,SG37,B003
6 | PG16,5 Novar Dr,Glasgow,G12 9AX,Flat,4,450,CO93,SG14,B003
7 |
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/projects.txt:
--------------------------------------------------------------------------------
1 | CPP Project P1 香安电力小区 6
2 | JAVA Project P2 哈高新区科技创新园核心区规划291路以西 3
3 | SQL Project P3 西钢大厦及西钢嘉苑小区 8
4 | 丽水丁香园小区既有物业服务 P4 哈尔滨市道里区工农街道办事处 4
5 | 哈尔滨开发-化工区集中供热扩建项目 P5 哈尔滨市香坊区化工路103号哈投股份热电厂-分厂院内 5
6 | 翠湖天地小区-翠园既有物业服务项目 P6 哈尔滨市道里区丽江路2842号 5
7 | 林海华庭小区物业服务 P7 林海华庭小区 9
8 | 哈尔滨市南岗区中发郦苑小区既有物业服务项目 P8 哈尔滨市南岗区先锋路591号 4
9 | 松北国际家居生活广场三期 P9 松北国际家居生活广场 3
10 | 中海文昌公馆项目 P10 南岗区文景街和文景头道街交口 6
11 | 珑瑞小区项目既有物业服务 P11 香坊区香大办事处通站社区 6
12 |
--------------------------------------------------------------------------------
/lab_4/extmem-c/extmem.layout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/departments.txt:
--------------------------------------------------------------------------------
1 | Research Department 1 45030219871218889X 2007-09-29
2 | Design Department 2 410303198712186359 2011-12-21
3 | Technology Department 3 350205199507128104 2011-11-14
4 | International Department 4 410303198712187415 2008-06-24
5 | Management Department 5 420505199107127334 2009-03-02
6 | Personal Department 6 350205199507127582 2012-12-09
7 | Business Department 7 23010319950712882X 2013-07-07
8 | Sale Department 8 45030219871218889X 2009-11-02
9 | Publicity Department 9 310105199107126115 2013-09-03
10 |
--------------------------------------------------------------------------------
/lab_4/lab_4/random_data.h:
--------------------------------------------------------------------------------
1 | #ifndef RANDOM_DATA_H
2 | #define RANDOM_DATA_H
3 |
4 | #define A_MAX 40
5 | #define A_MIN 1
6 | #define B_MAX 1000
7 | #define B_MIN 1
8 | #define C_MAX 60
9 | #define C_MIN 20
10 | #define D_MAX 1000
11 | #define D_MIN 1
12 |
13 | #define NUMBER_OF_R 112
14 | #define NUMBER_OF_S 224
15 |
16 | #define RANDOM_SEED 3
17 |
18 | typedef struct relationR {
19 | int a, b;
20 | } R;
21 |
22 | typedef struct relationS {
23 | int c, d;
24 | } S;
25 |
26 | R *randomGenerateRelationR();
27 |
28 | S *randomGenerateRelationS();
29 |
30 | #endif
--------------------------------------------------------------------------------
/lab_report_template/doc.tex:
--------------------------------------------------------------------------------
1 | \documentclass{ML}
2 |
3 | % 姓名,学号
4 | \infoauthor{朱明彦}{1160300314}
5 |
6 | % 课程类型,实验名称
7 | \infoexp{课程类型}{实验一}
8 |
9 | \infoschool{计算机学院}{高宏}
10 |
11 | \begin{document}
12 | \maketitle
13 |
14 | \tableofcontents
15 | \newpage
16 |
17 | \begin{center}
18 | \textbf{\zihao{3} 实验一 MySQL关系数据库管理系统及SQL语言的使用}
19 | \end{center}
20 |
21 | \section{实验目的}
22 |
23 | \section{实验环境}
24 |
25 | \section{实验过程及结果}
26 |
27 | \section{实验心得}
28 |
29 | % \appendix
30 |
31 | % \section{源代码}
32 | \section{参考文献}
33 | \begin{thebibliography}{20}
34 | % \bibitem{employee_name} 中国最常见名字前50名, \texttt{https://www.sohu.com/a/164406113\_367620}
35 | \bibitem{employee_id} 身份证号在线生成器, \texttt{https://www.tinysoft.org/}
36 | \end{thebibliography}
37 |
38 | \end{document}
39 |
--------------------------------------------------------------------------------
/lab_4/lab_4/random_data.c:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zmy on 19-4-22.
3 | //
4 |
5 | #include "random_data.h"
6 | #include
7 | #include
8 | #include
9 |
10 | R *randomGenerateRelationR() {
11 | R *r = (R *) malloc(NUMBER_OF_R * sizeof(R));
12 | int i;
13 | srand(RANDOM_SEED);
14 | for (i = 0; i < NUMBER_OF_R; i++) {
15 | int a = rand() % (A_MAX + 1 - A_MIN) + A_MIN;
16 | int b = rand() % (B_MAX + 1 - B_MIN) + B_MIN;
17 |
18 | r[i].a = a;
19 | r[i].b = b;
20 | }
21 | return r;
22 | }
23 |
24 |
25 | S *randomGenerateRelationS() {
26 | S *s = (S *) malloc(NUMBER_OF_S * sizeof(S));
27 | int i;
28 | srand(RANDOM_SEED);
29 | for (i = 0; i < NUMBER_OF_S; i++) {
30 | int c = rand() % (C_MAX + 1 - C_MIN) + C_MIN;
31 | int d = rand() % (D_MAX + 1 - D_MIN) + D_MIN;
32 |
33 | s[i].c = c;
34 | s[i].d = d;
35 | }
36 | return s;
37 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DataBase_2019_Spring
2 | 用于哈尔滨工业大学2019年春季数据库系统课程仓库
3 |
4 | ## 写在考试后
5 | ~~期末考试在儿童节,但题量仿佛做理综~~。从作业题来看,题目应该是邹老师出的,题型大概是5道选择,8道大题,大题最少有3问,最多有8问,题量特别巨大,可以说稍有犹豫可能就做不完,比如我。
6 |
7 | 涉及的知识点,简答和选择题主要是考察了基础概念,比如什么是数据独立性类似这种问题;其余七道大题,第二道是SQL和关系代数,涉及了`EXISTS`的使用,以及关系代数中涉及了如何实现SQL中的`GROUP BY`;第三道是范式,涉及了判断范式类型,模式分解,证明;第四道是B+树索引;第五道记不清了,印象中不太难;第六道涉及了两阶段锁协议以及冲突可并行化;第七道涉及日志恢复;第八道是ER图设计或者是IDEF1X二选一,最后一题15分。
8 |
9 | 除了考试之外,不同老师实验要求不一样,高老师是4次实验,前两次简单,只交报告不交代码;后两次,验收加交代码,不需要报告。实验四代码量很大。**总的来说,数据库课还是相当硬核的,TA极其认真负责,收获很大。**
10 |
11 | 写于数据库考试后
12 |
13 | ~~如果战神教你的话,可以期待一波超高分.~~
14 |
15 | ## 文件目录
16 | - homework_x为课程上1-6次作业
17 | - lab_x为课程上1-4次实验
18 | - Paper_Summary为论文summary
19 | - Prof. Zhaonian Zou 为Prof. Zhaonian Zou老师课程作业及答案
20 |
21 | ## Paper Summary
22 | 选择的论文为[Siqiang Luo, Ben Kao, Guoliang Li, Jiafeng Hu, Reynold Cheng, and Yudian Zheng. 2018. TOAIN: a throughput optimizing adaptive index for answering dynamic kNN queries on road networks. Proc. VLDB Endow. 11, 5 (January 2018), 594-606.](https://doi.org/10.1145/3187009.3177736)。
23 |
--------------------------------------------------------------------------------
/lab_2/BaseSetting.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{BaseSetting}[2018/3/13 v0.1 Report Template for Report]
3 |
4 | \LoadClass[11pt,a4paper,fancyhdr,fntef, UTF8]{ctexart}[2017/1/1]
5 |
6 | % 调整页面大小,默认页面与常用规格不符
7 | \RequirePackage[margin=1in,top=1.5in]{geometry}
8 |
9 | % 插入数学公式
10 | \RequirePackage{amsmath,amsthm,amsfonts,amssymb,bm}
11 |
12 | % 链接点击
13 | \RequirePackage{cite}
14 | \RequirePackage[colorlinks,linkcolor=black,anchorcolor=blue,citecolor=green]{hyperref}
15 |
16 | % 图表相关
17 | \RequirePackage{float,graphicx,tikz,pgfplots,array}
18 | % \usetikzlibrary{graphdrawing,graphs,trees,shapes,snakes,arrows,backgrounds}
19 | % \usegdlibrary{layered}
20 |
21 | % 用于插入C代码
22 | \RequirePackage{minted}
23 |
24 | % 设置页眉
25 | \usepackage{fancyhdr}
26 | \pagestyle{fancy}
27 | \fancyhf{} % 清空当前的页眉页脚
28 |
29 | %\fancyhead[L]{\heiti }
30 | %\fancyhead[R]{\heiti }
31 |
32 | \bibliographystyle{plain}
33 | \numberwithin{figure}{section}
34 |
35 | \ctexset{
36 | section={
37 | name={第,章},
38 | number=\arabic{section},
39 | format=\Large\bfseries\raggedright\heiti
40 | }
41 | }
42 |
43 | \newcommand\dlmu[2][4cm]{\hskip1pt\underline{\hb@xt@ #1{\hss#2\hss}}\hskip3pt}
44 |
45 | %\renewcommand\maketitle{%
46 | % \clearpage
47 | % \thispagestyle{empty}
48 | % \begin{center}
49 | %
50 | % \end{center}
51 | % \newpage
52 | %}
53 |
54 | \endinput
55 |
56 |
--------------------------------------------------------------------------------
/lab_1/report/BaseSetting.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{BaseSetting}[2018/3/13 v0.1 Report Template for Report]
3 |
4 | \LoadClass[11pt,a4paper,fancyhdr,fntef, UTF8]{ctexart}[2017/1/1]
5 |
6 | % 调整页面大小,默认页面与常用规格不符
7 | \RequirePackage[margin=1in,top=1.5in]{geometry}
8 |
9 | % 插入数学公式
10 | \RequirePackage{amsmath,amsthm,amsfonts,amssymb,bm}
11 |
12 | % 链接点击
13 | \RequirePackage{cite}
14 | \RequirePackage[colorlinks,linkcolor=black,anchorcolor=blue,citecolor=green]{hyperref}
15 |
16 | % 图表相关
17 | \RequirePackage{float,graphicx,tikz,pgfplots,array}
18 | % \usetikzlibrary{graphdrawing,graphs,trees,shapes,snakes,arrows,backgrounds}
19 | % \usegdlibrary{layered}
20 |
21 | % 用于插入C代码
22 | \RequirePackage{minted}
23 |
24 | % 设置页眉
25 | \usepackage{fancyhdr}
26 | \pagestyle{fancy}
27 | \fancyhf{} % 清空当前的页眉页脚
28 |
29 | %\fancyhead[L]{\heiti }
30 | %\fancyhead[R]{\heiti }
31 |
32 | \bibliographystyle{plain}
33 | \numberwithin{figure}{section}
34 |
35 | \ctexset{
36 | section={
37 | name={第,章},
38 | number=\arabic{section},
39 | format=\Large\bfseries\raggedright\heiti
40 | }
41 | }
42 |
43 | \newcommand\dlmu[2][4cm]{\hskip1pt\underline{\hb@xt@ #1{\hss#2\hss}}\hskip3pt}
44 |
45 | %\renewcommand\maketitle{%
46 | % \clearpage
47 | % \thispagestyle{empty}
48 | % \begin{center}
49 | %
50 | % \end{center}
51 | % \newpage
52 | %}
53 |
54 | \endinput
55 |
56 |
--------------------------------------------------------------------------------
/Paper_Summary/BaseSetting.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{BaseSetting}[2018/3/13 v0.1 Report Template for Report]
3 |
4 | \LoadClass[11pt,a4paper,fancyhdr,fntef, UTF8]{ctexart}[2017/1/1]
5 |
6 | % 调整页面大小,默认页面与常用规格不符
7 | \RequirePackage[margin=1in,top=1.5in]{geometry}
8 |
9 | % 插入数学公式
10 | \RequirePackage{amsmath,amsthm,amsfonts,amssymb,bm}
11 |
12 | % 链接点击
13 | \RequirePackage{cite}
14 | \RequirePackage[colorlinks,linkcolor=black,anchorcolor=blue,citecolor=green]{hyperref}
15 |
16 | % 图表相关
17 | \RequirePackage{float,graphicx,tikz,pgfplots,array}
18 | % \usetikzlibrary{graphdrawing,graphs,trees,shapes,snakes,arrows,backgrounds}
19 | % \usegdlibrary{layered}
20 |
21 | % 用于插入C代码
22 | \RequirePackage{minted}
23 |
24 | % 设置页眉
25 | \usepackage{fancyhdr}
26 | \pagestyle{fancy}
27 | \fancyhf{} % 清空当前的页眉页脚
28 |
29 | %\fancyhead[L]{\heiti }
30 | %\fancyhead[R]{\heiti }
31 |
32 | \bibliographystyle{plain}
33 | \numberwithin{figure}{section}
34 |
35 | \ctexset{
36 | section={
37 | name={第,章},
38 | number=\arabic{section},
39 | format=\Large\bfseries\raggedright\heiti
40 | }
41 | }
42 |
43 | \newcommand\dlmu[2][4cm]{\hskip1pt\underline{\hb@xt@ #1{\hss#2\hss}}\hskip3pt}
44 |
45 | %\renewcommand\maketitle{%
46 | % \clearpage
47 | % \thispagestyle{empty}
48 | % \begin{center}
49 | %
50 | % \end{center}
51 | % \newpage
52 | %}
53 |
54 | \endinput
55 |
56 |
--------------------------------------------------------------------------------
/lab_report_template/BaseSetting.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{BaseSetting}[2018/3/13 v0.1 Report Template for Report]
3 |
4 | \LoadClass[11pt,a4paper,fancyhdr,fntef, UTF8]{ctexart}[2017/1/1]
5 |
6 | % 调整页面大小,默认页面与常用规格不符
7 | \RequirePackage[margin=1in,top=1.5in]{geometry}
8 |
9 | % 插入数学公式
10 | \RequirePackage{amsmath,amsthm,amsfonts,amssymb,bm}
11 |
12 | % 链接点击
13 | \RequirePackage{cite}
14 | \RequirePackage[colorlinks,linkcolor=black,anchorcolor=blue,citecolor=green]{hyperref}
15 |
16 | % 图表相关
17 | \RequirePackage{float,graphicx,tikz,pgfplots,array}
18 | % \usetikzlibrary{graphdrawing,graphs,trees,shapes,snakes,arrows,backgrounds}
19 | % \usegdlibrary{layered}
20 |
21 | % 用于插入C代码
22 | \RequirePackage{minted}
23 |
24 | % 设置页眉
25 | \usepackage{fancyhdr}
26 | \pagestyle{fancy}
27 | \fancyhf{} % 清空当前的页眉页脚
28 |
29 | %\fancyhead[L]{\heiti }
30 | %\fancyhead[R]{\heiti }
31 |
32 | \bibliographystyle{plain}
33 | \numberwithin{figure}{section}
34 |
35 | \ctexset{
36 | section={
37 | name={第,章},
38 | number=\arabic{section},
39 | format=\Large\bfseries\raggedright\heiti
40 | }
41 | }
42 |
43 | \newcommand\dlmu[2][4cm]{\hskip1pt\underline{\hb@xt@ #1{\hss#2\hss}}\hskip3pt}
44 |
45 | %\renewcommand\maketitle{%
46 | % \clearpage
47 | % \thispagestyle{empty}
48 | % \begin{center}
49 | %
50 | % \end{center}
51 | % \newpage
52 | %}
53 |
54 | \endinput
55 |
56 |
--------------------------------------------------------------------------------
/lab_4/extmem-c/extmem.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/lab_4/lab_4/test.c:
--------------------------------------------------------------------------------
1 | /*
2 | * test.c
3 | * Zhaonian Zou
4 | * Harbin Institute of Technology
5 | * Jun 22, 2011
6 | */
7 |
8 | #include
9 | #include
10 | #include "extmem.h"
11 |
12 | int main(int argc, char **argv)
13 | {
14 | Buffer buf; /* A buffer */
15 | unsigned char *blk; /* A pointer to a block */
16 | int i = 0;
17 |
18 | /* Initialize the buffer */
19 | if (!initBuffer(20, 8, &buf))
20 | {
21 | perror("Buffer Initialization Failed!\n");
22 | return -1;
23 | }
24 |
25 | /* Get a new block in the buffer */
26 | blk = getNewBlockInBuffer(&buf);
27 |
28 | /* Fill data into the block */
29 | for (i = 0; i < 8; i++)
30 | *(blk + i) = 'a' + i;
31 |
32 | /* Write the block to the hard disk */
33 | if (writeBlockToDisk(blk, 31415926, &buf) != 0)
34 | {
35 | perror("Writing Block Failed!\n");
36 | return -1;
37 | }
38 |
39 | /* Read the block from the hard disk */
40 | if ((blk = readBlockFromDisk(31415926, &buf)) == NULL)
41 | {
42 | perror("Reading Block Failed!\n");
43 | return -1;
44 | }
45 |
46 | /* Process the data in the block */
47 | for (i = 0; i < 8; i++)
48 | printf("%c", *(blk + i));
49 |
50 | printf("\n");
51 | printf("# of IO's is %d\n", buf.numIO); /* Check the number of IO's */
52 |
53 | return 0;
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/lab_4/extmem-c/test.c:
--------------------------------------------------------------------------------
1 | /*
2 | * test.c
3 | * Zhaonian Zou
4 | * Harbin Institute of Technology
5 | * Jun 22, 2011
6 | */
7 |
8 | #include
9 | #include
10 | #include "extmem.h"
11 |
12 | int main(int argc, char **argv)
13 | {
14 | Buffer buf; /* A buffer */
15 | unsigned char *blk; /* A pointer to a block */
16 | int i = 0;
17 |
18 | /* Initialize the buffer */
19 | if (!initBuffer(20, 8, &buf))
20 | {
21 | perror("Buffer Initialization Failed!\n");
22 | return -1;
23 | }
24 |
25 | /* Get a new block in the buffer */
26 | blk = getNewBlockInBuffer(&buf);
27 |
28 | /* Fill data into the block */
29 | for (i = 0; i < 8; i++)
30 | *(blk + i) = 'a' + i;
31 |
32 | /* Write the block to the hard disk */
33 | if (writeBlockToDisk(blk, 31415926, &buf) != 0)
34 | {
35 | perror("Writing Block Failed!\n");
36 | return -1;
37 | }
38 |
39 | /* Read the block from the hard disk */
40 | if ((blk = readBlockFromDisk(31415926, &buf)) == NULL)
41 | {
42 | perror("Reading Block Failed!\n");
43 | return -1;
44 | }
45 |
46 | /* Process the data in the block */
47 | for (i = 0; i < 8; i++)
48 | printf("%c", *(blk + i));
49 |
50 | printf("\n");
51 | printf("# of IO's is %d\n", buf.numIO); /* Check the number of IO's */
52 |
53 | return 0;
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/Paper_Summary/ml.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{ML}[2018/3/13 v0.1 Report Template for Software Configuration]
3 |
4 | \LoadClass{BaseSetting}[2017/1/1]
5 |
6 | \fancyhead[L]{\heiti 论文概述}
7 | \fancyhead[R]{\heiti \ML@value@expname}
8 | \fancyfoot[R]{\thepage}
9 |
10 | % 姓名,学号
11 | \newcommand\infoauthor[2]{\def\ML@value@author{#1} \def\ML@value@ident{#2} }
12 |
13 | % 课程类型,实验名称
14 | \newcommand\infoexp[2]{\def\ML@value@classtype{#1} \def\ML@value@expname{#2}}
15 | %
16 | \newcommand\infoschool[2]{\def\ML@value@school{#1} \def\ML@value@teacher{#2}}
17 |
18 | \renewcommand\maketitle{%
19 | \clearpage
20 | \thispagestyle{empty}
21 | \begin{center}
22 | \rule[1.10cm]{\linewidth}{0cm}
23 | \includegraphics[width=0.9\linewidth]{media/HIT}
24 |
25 | \vspace{0.5cm}
26 |
27 | \textbf{\zihao{0} 数据库系统}
28 |
29 | \vspace{1.5cm}
30 |
31 | \textbf{\zihao{2} 论文概述}
32 |
33 | \vspace{1.5cm}
34 |
35 | \textbf{\zihao{2} (2019年度春季学期)}
36 |
37 | \begin{LARGE}
38 | \vspace{2cm}
39 | 姓\rule{38pt}{0pt}名 \dlmu[6cm]{\ML@value@author}\\ \vspace{4pt}
40 | 学\rule{38pt}{0pt}号 \dlmu[6cm]{\ML@value@ident}\\ \vspace{4pt}
41 | 学\rule{38pt}{0pt}院 \dlmu[6cm]{\ML@value@school} \\ \vspace{4pt}
42 | 教\rule{38pt}{0pt}师 \dlmu[6cm]{\ML@value@teacher} \\ \vspace{4pt}
43 | \end{LARGE}
44 |
45 | \vfill
46 | {\huge \textbf{计算机科学与技术学院}}
47 | \end{center}
48 | \newpage
49 | }
50 |
51 | \endinput
52 |
--------------------------------------------------------------------------------
/lab_2/ml.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{ML}[2018/3/13 v0.1 Report Template for Software Configuration]
3 |
4 | \LoadClass{BaseSetting}[2017/1/1]
5 |
6 | \fancyhead[L]{\heiti 数据库系统课程实验报告}
7 | \fancyhead[R]{\heiti \ML@value@expname}
8 | \fancyfoot[R]{\thepage}
9 |
10 | % 姓名,学号
11 | \newcommand\infoauthor[2]{\def\ML@value@author{#1} \def\ML@value@ident{#2} }
12 |
13 | % 课程类型,实验名称
14 | \newcommand\infoexp[2]{\def\ML@value@classtype{#1} \def\ML@value@expname{#2}}
15 | %
16 | \newcommand\infoschool[2]{\def\ML@value@school{#1} \def\ML@value@teacher{#2}}
17 |
18 | \renewcommand\maketitle{%
19 | \clearpage
20 | \thispagestyle{empty}
21 | \begin{center}
22 | \rule[1.10cm]{\linewidth}{0cm}
23 | \includegraphics[width=0.9\linewidth]{media/HIT}
24 |
25 | \vspace{0.5cm}
26 |
27 | \textbf{\zihao{0} 数据库系统}
28 |
29 | \vspace{1.5cm}
30 |
31 | \textbf{\zihao{2} 实验报告之二}
32 |
33 | \vspace{1.5cm}
34 |
35 | \textbf{\zihao{2} (2019年度春季学期)}
36 |
37 | \begin{LARGE}
38 | \vspace{2cm}
39 | 姓\rule{38pt}{0pt}名 \dlmu[6cm]{\ML@value@author}\\ \vspace{4pt}
40 | 学\rule{38pt}{0pt}号 \dlmu[6cm]{\ML@value@ident}\\ \vspace{4pt}
41 | 学\rule{38pt}{0pt}院 \dlmu[6cm]{\ML@value@school} \\ \vspace{4pt}
42 | 教\rule{38pt}{0pt}师 \dlmu[6cm]{\ML@value@teacher} \\ \vspace{4pt}
43 | \end{LARGE}
44 |
45 | \vfill
46 | {\huge \textbf{计算机科学与技术学院}}
47 | \end{center}
48 | \newpage
49 | }
50 |
51 | \endinput
52 |
--------------------------------------------------------------------------------
/lab_1/report/ml.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{ML}[2018/3/13 v0.1 Report Template for Software Configuration]
3 |
4 | \LoadClass{BaseSetting}[2017/1/1]
5 |
6 | \fancyhead[L]{\heiti 数据库系统课程实验报告}
7 | \fancyhead[R]{\heiti \ML@value@expname}
8 | \fancyfoot[R]{\thepage}
9 |
10 | % 姓名,学号
11 | \newcommand\infoauthor[2]{\def\ML@value@author{#1} \def\ML@value@ident{#2} }
12 |
13 | % 课程类型,实验名称
14 | \newcommand\infoexp[2]{\def\ML@value@classtype{#1} \def\ML@value@expname{#2}}
15 | %
16 | \newcommand\infoschool[2]{\def\ML@value@school{#1} \def\ML@value@teacher{#2}}
17 |
18 | \renewcommand\maketitle{%
19 | \clearpage
20 | \thispagestyle{empty}
21 | \begin{center}
22 | \rule[1.10cm]{\linewidth}{0cm}
23 | \includegraphics[width=0.9\linewidth]{media/HIT}
24 |
25 | \vspace{0.5cm}
26 |
27 | \textbf{\zihao{0} 数据库系统}
28 |
29 | \vspace{1.5cm}
30 |
31 | \textbf{\zihao{2} 实验报告之一}
32 |
33 | \vspace{1.5cm}
34 |
35 | \textbf{\zihao{2} (2019年度春季学期)}
36 |
37 | \begin{LARGE}
38 | \vspace{2cm}
39 | 姓\rule{38pt}{0pt}名 \dlmu[6cm]{\ML@value@author}\\ \vspace{4pt}
40 | 学\rule{38pt}{0pt}号 \dlmu[6cm]{\ML@value@ident}\\ \vspace{4pt}
41 | 学\rule{38pt}{0pt}院 \dlmu[6cm]{\ML@value@school} \\ \vspace{4pt}
42 | 教\rule{38pt}{0pt}师 \dlmu[6cm]{\ML@value@teacher} \\ \vspace{4pt}
43 | \end{LARGE}
44 |
45 | \vfill
46 | {\huge \textbf{计算机科学与技术学院}}
47 | \end{center}
48 | \newpage
49 | }
50 |
51 | \endinput
52 |
--------------------------------------------------------------------------------
/lab_report_template/ml.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | \ProvidesClass{ML}[2018/3/13 v0.1 Report Template for Software Configuration]
3 |
4 | \LoadClass{BaseSetting}[2017/1/1]
5 |
6 | \fancyhead[L]{\heiti 数据库系统课程实验报告}
7 | \fancyhead[R]{\heiti \ML@value@expname}
8 | \fancyfoot[R]{\thepage}
9 |
10 | % 姓名,学号
11 | \newcommand\infoauthor[2]{\def\ML@value@author{#1} \def\ML@value@ident{#2} }
12 |
13 | % 课程类型,实验名称
14 | \newcommand\infoexp[2]{\def\ML@value@classtype{#1} \def\ML@value@expname{#2}}
15 | %
16 | \newcommand\infoschool[2]{\def\ML@value@school{#1} \def\ML@value@teacher{#2}}
17 |
18 | \renewcommand\maketitle{%
19 | \clearpage
20 | \thispagestyle{empty}
21 | \begin{center}
22 | \rule[1.10cm]{\linewidth}{0cm}
23 | \includegraphics[width=0.9\linewidth]{media/HIT}
24 |
25 | \vspace{0.5cm}
26 |
27 | \textbf{\zihao{0} 数据库系统}
28 |
29 | \vspace{1.5cm}
30 |
31 | \textbf{\zihao{2} 实验报告之一}
32 |
33 | \vspace{1.5cm}
34 |
35 | \textbf{\zihao{2} (2019年度春季学期)}
36 |
37 | \begin{LARGE}
38 | \vspace{2cm}
39 | 姓\rule{38pt}{0pt}名 \dlmu[6cm]{\ML@value@author}\\ \vspace{4pt}
40 | 学\rule{38pt}{0pt}号 \dlmu[6cm]{\ML@value@ident}\\ \vspace{4pt}
41 | 学\rule{38pt}{0pt}院 \dlmu[6cm]{\ML@value@school} \\ \vspace{4pt}
42 | 教\rule{38pt}{0pt}师 \dlmu[6cm]{\ML@value@teacher} \\ \vspace{4pt}
43 | \end{LARGE}
44 |
45 | \vfill
46 | {\huge \textbf{计算机科学与技术学院}}
47 | \end{center}
48 | \newpage
49 | }
50 |
51 | \endinput
52 |
--------------------------------------------------------------------------------
/lab_4/lab_4/extmem.h:
--------------------------------------------------------------------------------
1 | /*
2 | * extmem.h
3 | * Zhaonian Zou
4 | * Harbin Institute of Technology
5 | * Jun 22, 2011
6 | */
7 |
8 | #ifndef EXTMEM_H
9 | #define EXTMEM_H
10 |
11 | #define BLOCK_AVAILABLE 0
12 | #define BLOCK_UNAVAILABLE 1
13 |
14 | typedef struct tagBuffer {
15 | unsigned long numIO; /* Number of IO's*/
16 | size_t bufSize; /* Buffer size*/
17 | size_t blkSize; /* Block size */
18 | size_t numAllBlk; /* Number of blocks that can be kept in the buffer */
19 | size_t numFreeBlk; /* Number of available blocks in the buffer */
20 | unsigned char *data; /* Starting address of the buffer */
21 | } Buffer;
22 |
23 | /* Initialize a buffer with the specified buffer size and block size.
24 | * If the initialization fails, the return value is NULL;
25 | * otherwise the pointer to the buffer.
26 | */
27 | Buffer *initBuffer(size_t bufSize, size_t blkSize, Buffer *buf);
28 |
29 | /* Free the memory used by a buffer. */
30 | void freeBuffer(Buffer *buf);
31 |
32 | /* Apply for a new block from a buffer.
33 | * If no free blocks are available in the buffer,
34 | * then the return value is NULL; otherwise the pointer to the block.
35 | */
36 | unsigned char *getNewBlockInBuffer(Buffer *buf);
37 |
38 | /* Set a block in a buffer to be available. */
39 | void freeBlockInBuffer(unsigned char *blk, Buffer *buf);
40 |
41 | /* Drop a block on the disk */
42 | int dropBlockOnDisk(unsigned int addr);
43 |
44 | /* Read a block from the hard disk to the buffer by the address of the block. */
45 | unsigned char *readBlockFromDisk(unsigned int addr, Buffer *buf);
46 |
47 | /* Read a block in the buffer to the hard disk by the address of the block. */
48 | int writeBlockToDisk(unsigned char *blkPtr, unsigned int addr, Buffer *buf);
49 |
50 | #endif // EXTMEM_H
51 |
--------------------------------------------------------------------------------
/lab_4/extmem-c/extmem.h:
--------------------------------------------------------------------------------
1 | /*
2 | * extmem.h
3 | * Zhaonian Zou
4 | * Harbin Institute of Technology
5 | * Jun 22, 2011
6 | */
7 |
8 | #ifndef EXTMEM_H
9 | #define EXTMEM_H
10 |
11 | #define BLOCK_AVAILABLE 0
12 | #define BLOCK_UNAVAILABLE 1
13 |
14 | typedef struct tagBuffer {
15 | unsigned long numIO; /* Number of IO's*/
16 | size_t bufSize; /* Buffer size*/
17 | size_t blkSize; /* Block size */
18 | size_t numAllBlk; /* Number of blocks that can be kept in the buffer */
19 | size_t numFreeBlk; /* Number of available blocks in the buffer */
20 | unsigned char *data; /* Starting address of the buffer */
21 | } Buffer;
22 |
23 | /* Initialize a buffer with the specified buffer size and block size.
24 | * If the initialization fails, the return value is NULL;
25 | * otherwise the pointer to the buffer.
26 | */
27 | Buffer *initBuffer(size_t bufSize, size_t blkSize, Buffer *buf);
28 |
29 | /* Free the memory used by a buffer. */
30 | void freeBuffer(Buffer *buf);
31 |
32 | /* Apply for a new block from a buffer.
33 | * If no free blocks are available in the buffer,
34 | * then the return value is NULL; otherwise the pointer to the block.
35 | */
36 | unsigned char *getNewBlockInBuffer(Buffer *buf);
37 |
38 | /* Set a block in a buffer to be available. */
39 | void freeBlockInBuffer(unsigned char *blk, Buffer *buf);
40 |
41 | /* Drop a block on the disk */
42 | int dropBlockOnDisk(unsigned int addr);
43 |
44 | /* Read a block from the hard disk to the buffer by the address of the block. */
45 | unsigned char *readBlockFromDisk(unsigned int addr, Buffer *buf);
46 |
47 | /* Read a block in the buffer to the hard disk by the address of the block. */
48 | int writeBlockToDisk(unsigned char *blkPtr, unsigned int addr, Buffer *buf);
49 |
50 | #endif // EXTMEM_H
51 |
--------------------------------------------------------------------------------
/lab_3/lab_3/README.md:
--------------------------------------------------------------------------------
1 | # 基本表
2 | - 分公司表(Branch)(公司编号(Branch_no), 街道(Street), 城市(City), 邮编(Postcode))
3 | - 分公司电话表(Branch_Tel)(公司编号(Branch_no), 电话号码(Tel))
4 | - 员工表(Staff)(员工编号(Staff_no), 员工名字(Staff_name), 职位(Staff_position), 员工性别(Staff_gender), 主管编号(Staff_superior), 员工工资(Staff_salary), 所在分公司(Staff_branch))
5 | - 经理表(Manager)(员工编号(Staff_no), 公司编号(Branch_no), 经理奖金(Manager_bonus), 经历任职日期(Manager_start))
6 | - 出租的房产(PropertyForRent)(Property_no,Street,City,Postcode,Type,Rooms,Rent,Owner_no,Staff_no)
7 | - 私人业主(PrivateOwner)(Owner_no,Name,Address,Tel_no)
8 | - 企业业主(BusinessOwner)(Owner_no,Name,Address,Tel_no, Type, Contact)
9 | - 客户(Client)(Client_no, name, Tel_no, Preftype, Maxrent)
10 | - 报纸(Newspaper)(Name, Tel_no, Address, Contact_name)
11 | - 广告(Advertisement)(Newspaper_name, Ad_date, Property_no, Ad_rent)
12 | - 看房(Viewing)(Client_no,Propertyno,View_date,commnt)
13 | - 租约(Lease)(Lease_no, Client_no, Property_no, Rent, Deposit, Deposit_whether, Payment, Lease_length, Lease_start, Lease_end)
14 |
15 | # Branch视图(分公司视图)
16 | ## 数据录入
17 | 1. 录入一个新的分公司情况
18 | 2. 录入某个分公司中一名新员工的情况
19 | 3. 录入客户和房产之间新的租约情况
20 | 4. 录入在报纸上刊登广告的情况
21 | ## 数据删除
22 | 5. 删除某个分公司的情况
23 | 6. 删除工作在某个分公司的一名员工的情况
24 | 7. 删除给定租约的情况
25 | 8. 删除给定报纸的广告情况
26 | ## 数据查询
27 | 1. 列出给定城市所有分公司的情况(连接查询)
28 | 2. 列出给定分公司员工的名字,职务,工资和管理房产的总数(连接查询 分组查询)
29 | 3. 列出刊登过广告的房产的详细情况(嵌套查询)
30 | 4. 列出由企业业主提供的房产的情况(嵌套查询)
31 | 5. 等等...
32 | ## 索引
33 | 在Staff表上增加相对于Staff_name的索引.
34 | ## Trigger 和 事务处理
35 | - 每名员工的最低工资为9000元, 当低于9000是自动改为9000.
36 | - 删除和增减工资时必须手动确认, 且不能中途停止.(待完善)
37 |
38 |
39 | # Staff视图(员工视图) TODO
40 | ## 数据录入
41 | 1. 录入某个待租的的新房产及其业主的情况
42 | 2. 录入一名新客户的情况
43 | 3. 录入一名客户查看房产的情况
44 | 4. 录入客户对房产签约的情况
45 |
46 | ## 数据删除
47 | 1. 删除一处房产的情况
48 | 2. 删除一名业主的情况
49 | 3. 删除一名客户的情况
50 | 4. 删除一名客户查看过一处房产的情况
51 | 5. 删除一份租约的情况
52 |
53 | ## 数据查询
54 | 1. 按字典序列出所有助理的情况
55 | 2. 列出没有给出评论的房产的情况
56 | 3. 等等...
57 |
58 |
59 |
60 |
61 | # 参考
62 | - [DreamHome_Ref_Data来源](http://www.ccs.neu.edu/home/ekanou/teaching/spring04/CSG102/dreamHome/)
63 |
--------------------------------------------------------------------------------
/lab_4/lab_4/README.md:
--------------------------------------------------------------------------------
1 | # Lab 4
2 |
3 | ## 文件说明
4 | - `extmem.h, extmem.c`为实验所提供的库,版权为[邹兆年老师](http://homepage.hit.edu.cn/zou)所有。
5 | - `test.c`为实验所提供的库文件使用参考。
6 | - `random.h, random.c`为随机生成实验数据,其中R关系112条元组,S关系224条元组。
7 | - `lab4.c`为此次实验的主要文件。
8 |
9 | ## 关于ExtMem库的一些注意事项
10 | 1. `numFreeBlk` 可能比 `numAllBlk`还大,所以`numFreeBlk`没有参考价值,其更新过于混乱。
11 | 2. 在使用`writeBlockToDisk`函数后无需手动释放输出缓存,已经在函数内部Free过了。
12 |
13 | ## 使用ExtMem库的我所遵守的一些原则
14 | 1. 在使用后将函数内局部使用的Buffer Block释放,保持调用函数前后缓存中的block数目不变。
15 | 2. 使用的所有函数都遵循`test.c`中给出的原则。
16 |
17 | ## 存储元组的方式
18 | **以下表示均为示意性的,真实的表示中仅有括号内的整数且按照2进制存储。**
19 | 1. 对于普通的关系(有2个integer类型的属性)存储格式为
20 | ```
21 | 40000 (20, 916, 20, 787, 21, 926, 21, 556, 21, 726, 22, 903, 22, 423, 40064, 0)
22 | ```
23 | 其中第一个整数为块地址,括号内的两个为一组,如`20, 916`表示一个元组,每一个块内保存7个元组;对于最后8个字节,前4个字节保存下一个块的地址(如果为0表示没有下一块),最后4个字节为0。
24 |
25 | 2. 对于投影后的关系(有1个integer类型的属性)存储格式为
26 | ```
27 | 60000 (2, 2, 2, 3, 3, 3, 4, 6, 7, 7, 8, 9, 9, 9, 9, 60064)
28 | ```
29 | 其中第一个仍然为块地址,括号内每一个整数为投影后的一个元组,每一个块内可以保存15个元组;对于最后4个字节保存下一个块的地址(如果为0表示没有下一块)。
30 |
31 | 3. 对于连接后的关系(有3个integer类型的属性)存储格式为
32 | ```
33 | 70000 (40, 790, 925, 40, 790, 572, 40, 790, 924, 40, 790, 14, 40, 790, 245, 70064)
34 | ```
35 | 其中第一个仍然是块地址,括号内每3个整数为连接后的一个元组(其中第1个整数为R.A和S.C,第2个整数为R.B,第3个整数为S.D);最后4个字节表示下一个块的地址(如果为0则表示没有下一个块)。
36 |
37 | 4. 对于B+ Tree里面节点的存储,主要有两种分别是内节点的存储和叶子节点的存储,且使用的B+ Tree的度为6。
38 |
39 | 1. 内节点的存储
40 | ```
41 | 80000 (80064, 8, 80128, 16, 80192, 22, 80256, 29, 80320, 35, 80384, 0, 0, 0, 0, -1)
42 | ```
43 | 其中最后4个字节为-1,表示这是一个内节点;由于度为6,所以在存储内节点的块的倒数5-12字节均为0;除此以外,从开始的偶数4字节处记录的是,有小于紧跟其后4字节记录的整数对应的索引属性并且大于等于其左侧4字节记录整数对应的索引属性的元组。
44 |
45 | 2. 叶节点的存储
46 | ```
47 | 80064 (1, 50000, 2, 50000, 3, 50000, 4, 50064, 6, 50064, 7, 50064, 0, 0, 0, 0)
48 | ```
49 | 由于度为6,所以每一个叶子块的最后16字节为0;从开始的偶数4字节为索引属性的值,紧跟其后的奇数4字节为对应包含该索引属性值的块地址。
50 |
51 | 5. 对于hash函数得到的桶,其存储格式为
52 | ```
53 | 1001344 (40, 924, 40, 14, 40, 245, 20, 90, 20, 176, 40, 700, 60, 81, 1002240, 7)
54 | 1002240 (40, 430, 40, 213, 60, 284, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3)
55 | ```
56 | 其中第一个整数表示该块的地址;最后8个字节,前4个字节表示如果该桶如果有下一个块存在,则为对应的块地址,如果没有下一个块存在则其为0,后4个字节表示该块内已经记录的元组个数,如对于第一条记录,其记录了7条元组。
57 |
--------------------------------------------------------------------------------
/lab_3/lab_3/src/sample/Main.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | import java.sql.*;
10 | import java.util.Objects;
11 |
12 | public class Main extends Application {
13 |
14 | // JDBC 驱动名及数据库 URL
15 | private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
16 | private static final String DB_URL = "jdbc:mysql://localhost:3306/DreamHome";
17 |
18 | // 数据库的用户名与密码,需要根据自己的设置
19 | private static final String USER = "root";
20 | private static final String PASS = "mysql";
21 |
22 | public static Connection connection;
23 | public static Statement statement;
24 |
25 | @Override
26 | public void start(Stage primaryStage) throws Exception {
27 | Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
28 | primaryStage.setTitle("DreamHome");
29 | primaryStage.setScene(new Scene(root, 600, 400));
30 | primaryStage.show();
31 | }
32 |
33 | public static void main(String[] args) {
34 | try {
35 | // 注册 JDBC 驱动
36 | Class.forName(JDBC_DRIVER);
37 |
38 | // 打开链接
39 | System.out.println("连接数据库...");
40 | connection = DriverManager.getConnection(DB_URL, USER, PASS);
41 |
42 | // 执行查询
43 |
44 | if (!connection.isClosed()) {
45 | System.out.println("Connection Successful!");
46 |
47 | System.out.println(" 实例化Statement对象...");
48 | statement = connection.createStatement();
49 |
50 | launch(args);
51 | }
52 | statement.close();
53 | connection.close();
54 | } catch (Exception se) {
55 | // 处理 JDBC 错误
56 | se.printStackTrace();
57 | }// 处理 Class.forName 错误
58 | finally {
59 | // 关闭资源
60 | try {
61 | if (statement != null) statement.close();
62 | } catch (SQLException ignored) {
63 | }// 什么都不做
64 | try {
65 | if (connection != null) connection.close();
66 | } catch (SQLException se) {
67 | se.printStackTrace();
68 | }
69 | }
70 | System.out.println("Goodbye!");
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/employee_id.txt:
--------------------------------------------------------------------------------
1 | 彭龙全 513436200003186558
2 | 倪山 513436200003187059
3 | 周世华 513436200003188211
4 | 王仪叶 513436200003189150
5 | 于凝刚 513436200003189273
6 | 太叔玛 51343620000318945X
7 | 长孙韦 513436200003188393
8 | 裘世 513436200003189492
9 | 封明 513436200003188297
10 | 何强辉 513436200003188676
11 | 阙亚 513436200003189353
12 | 霍紫瑾 513436200003186996
13 | 宗勤 513436200003188916
14 | 关琴 230103199507126541
15 | 齐娟 230103199507129080
16 | 马豪 230103199507128803
17 | 丁江毓 230103199507129347
18 | 柏蝶平 230103199507126568
19 | 溥羽娴 230103199507129726
20 | 桑桂 230103199507128483
21 | 裘启竹 230103199507129785
22 | 姜策春 23010319950712882X
23 | 石程 230103199507127560
24 | 习贝 230103199507129427
25 | 裴纯晶 230103199507128360
26 | 叶中晶 230103199507128205
27 | 耿伊 35020519950712754X
28 | 赫连友 350205199507127507
29 | 庾政 350205199507129844
30 | 云学彩 350205199507127769
31 | 庄红永 350205199507129043
32 | 荀露 350205199507128729
33 | 冉有 350205199507127582
34 | 景兴绍 350205199507128921
35 | 郭恒月 350205199507128366
36 | 路言良 350205199507129908
37 | 谈怡奇 350205199507126387
38 | 周淑言 350205199507128104
39 | 闻莲谦 350205199507127101
40 | 荆和炎 42050519910712845X
41 | 伊芬 420505199107129292
42 | 穆贞 420505199107127078
43 | 江瑞 420505199107127334
44 | 葛邦泰 420505199107127414
45 | 齐政策 420505199107129532
46 | 幸功 420505199107126550
47 | 沈羽 420505199107127393
48 | 阮育轮 420505199107128097
49 | 屈烟纨 420505199107128353
50 | 师强 420505199107128513
51 | 杨以 420505199107127772
52 | 屈广 310105199107127898
53 | 封鸿馨 310105199107126377
54 | 姜梅 310105199107128372
55 | 欧胜 310105199107127732
56 | 司马善 310105199107127599
57 | 池恒 310105199107126756
58 | 戴宏蝶 310105199107129279
59 | 申屠影 310105199107126510
60 | 马军 310105199107129914
61 | 阙明韦 310105199107126537
62 | 孟祥霭 310105199107129439
63 | 管聪宇 310105199107126131
64 | 禄艳珠 310105199107126115
65 | 桑锦唯 450302198712186632
66 | 唐玛 450302198712188734
67 | 魏裕 450302198712187870
68 | 姚咏咏 450302198712188013
69 | 惠红纨 450302198712188195
70 | 太叔滢 450302198712187539
71 | 沈真 45030219871218889X
72 | 怀彦翰 450302198712187539
73 | 仲孙言 450302198712186712
74 | 缪露 450302198712189673
75 | 雷致 450302198712189032
76 | 韩良俊 450302198712188873
77 | 童洋顺 450302198712188558
78 | 路恒萍 410303198712188530
79 | 夏侯行 410303198712188477
80 | 上官唯 410303198712187917
81 | 张红 410303198712187415
82 | 苗栋发 410303198712187650
83 | 易倩茗 410303198712189672
84 | 卓锦婕 410303198712189170
85 | 云彩弘 410303198712188899
86 | 邵顺 410303198712188274
87 | 秦瑶 410303198712187634
88 | 骆瑞 41030319871218605X
89 | 姚香 41030319871218779X
90 | 瞿泰承 410303198712186359
--------------------------------------------------------------------------------
/lab_4/extmem-c/extmem.c:
--------------------------------------------------------------------------------
1 | /*
2 | * extmem.c
3 | * Zhaonian Zou
4 | * Harbin Institute of Technology
5 | * Jun 22, 2011
6 | */
7 |
8 | #include
9 | #include
10 | #include "extmem.h"
11 |
12 | Buffer *initBuffer(size_t bufSize, size_t blkSize, Buffer *buf)
13 | {
14 | int i;
15 |
16 | buf->numIO = 0;
17 | buf->bufSize = bufSize;
18 | buf->blkSize = blkSize;
19 | buf->numAllBlk = bufSize / (blkSize + 1);
20 | buf->numFreeBlk = buf->numAllBlk;
21 | buf->data = (unsigned char*)malloc(bufSize * sizeof(unsigned char));
22 |
23 | if (!buf->data)
24 | {
25 | perror("Buffer Initialization Failed!\n");
26 | return NULL;
27 | }
28 |
29 | memset(buf->data, 0, bufSize * sizeof(unsigned char));
30 | return buf;
31 | }
32 |
33 | void freeBuffer(Buffer *buf)
34 | {
35 | free(buf->data);
36 | }
37 |
38 | unsigned char *getNewBlockInBuffer(Buffer *buf)
39 | {
40 | unsigned char *blkPtr;
41 |
42 | if (buf->numFreeBlk == 0)
43 | {
44 | perror("Buffer is full!\n");
45 | return NULL;
46 | }
47 |
48 | blkPtr = buf->data;
49 |
50 | while (blkPtr < buf->data + (buf->blkSize + 1) * buf->numAllBlk)
51 | {
52 | if (*blkPtr == BLOCK_AVAILABLE)
53 | break;
54 | else
55 | blkPtr += buf->blkSize + 1;
56 | }
57 |
58 | *blkPtr = BLOCK_UNAVAILABLE;
59 | buf->numFreeBlk--;
60 | return blkPtr + 1;
61 | }
62 |
63 | void freeBlockInBuffer(unsigned char *blk, Buffer *buf)
64 | {
65 | *(blk - 1) = BLOCK_AVAILABLE;
66 | buf->numFreeBlk++;
67 | }
68 |
69 | int dropBlockOnDisk(unsigned int addr)
70 | {
71 | char filename[40];
72 |
73 | sprintf(filename, "%d.blk", addr);
74 |
75 | if (remove(filename) == -1)
76 | {
77 | perror("Dropping Block Fails!\n");
78 | return -1;
79 | }
80 |
81 | return 0;
82 | }
83 |
84 | unsigned char *readBlockFromDisk(unsigned int addr, Buffer *buf)
85 | {
86 | char filename[40];
87 | unsigned char *blkPtr, *bytePtr;
88 | char ch;
89 |
90 | if (buf->numFreeBlk == 0)
91 | {
92 | perror("Buffer Overflows!\n");
93 | return NULL;
94 | }
95 |
96 | blkPtr = buf->data;
97 |
98 | while (blkPtr < buf->data + (buf->blkSize + 1) * buf->numAllBlk)
99 | {
100 | if (*blkPtr == BLOCK_AVAILABLE)
101 | break;
102 | else
103 | blkPtr += buf->blkSize + 1;
104 | }
105 |
106 | sprintf(filename, "%d.blk", addr);
107 | FILE *fp = fopen(filename, "rb");
108 |
109 | if (!fp)
110 | {
111 | perror("Reading Block Failed!\n");
112 | return NULL;
113 | }
114 |
115 | *blkPtr = BLOCK_UNAVAILABLE;
116 | blkPtr++;
117 | bytePtr = blkPtr;
118 |
119 | while (bytePtr < blkPtr + buf->blkSize)
120 | {
121 | ch = fgetc(fp);
122 | *bytePtr = ch;
123 | bytePtr++;
124 | }
125 |
126 | fclose(fp);
127 | buf->numFreeBlk--;
128 | buf->numIO++;
129 | return blkPtr;
130 | }
131 |
132 | int writeBlockToDisk(unsigned char *blkPtr, unsigned int addr, Buffer *buf)
133 | {
134 | char filename[40];
135 | unsigned char *bytePtr;
136 |
137 | sprintf(filename, "%d.blk", addr);
138 | FILE *fp = fopen(filename, "wb");
139 |
140 | if (!fp)
141 | {
142 | perror("Writing Block Failed!\n");
143 | return -1;
144 | }
145 |
146 | for (bytePtr = blkPtr; bytePtr < blkPtr + buf->blkSize; bytePtr++)
147 | fputc((int)(*bytePtr), fp);
148 |
149 | fclose(fp);
150 | *(blkPtr - 1) = BLOCK_AVAILABLE;
151 | buf->numFreeBlk++;
152 | buf->numIO++;
153 | return 0;
154 | }
155 |
--------------------------------------------------------------------------------
/lab_4/lab_4/extmem.c:
--------------------------------------------------------------------------------
1 | /*
2 | * extmem.c
3 | * Zhaonian Zou
4 | * Harbin Institute of Technology
5 | * Jun 22, 2011
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include "extmem.h"
12 |
13 | Buffer *initBuffer(size_t bufSize, size_t blkSize, Buffer *buf)
14 | {
15 | int i;
16 |
17 | buf->numIO = 0;
18 | buf->bufSize = bufSize;
19 | buf->blkSize = blkSize;
20 | buf->numAllBlk = bufSize / (blkSize + 1);
21 | buf->numFreeBlk = buf->numAllBlk;
22 | // TODO BUG numFreeBlk can be bigger than numAllBlk.
23 | buf->data = (unsigned char*)malloc(bufSize * sizeof(unsigned char));
24 |
25 | if (!buf->data)
26 | {
27 | perror("Buffer Initialization Failed!\n");
28 | return NULL;
29 | }
30 |
31 | memset(buf->data, 0, bufSize * sizeof(unsigned char));
32 | return buf;
33 | }
34 |
35 | void freeBuffer(Buffer *buf)
36 | {
37 | free(buf->data);
38 | }
39 |
40 | unsigned char *getNewBlockInBuffer(Buffer *buf)
41 | {
42 | unsigned char *blkPtr;
43 |
44 | if (buf->numFreeBlk == 0)
45 | {
46 | perror("Buffer is full!\n");
47 | return NULL;
48 | }
49 |
50 | blkPtr = buf->data;
51 |
52 | while (blkPtr < buf->data + (buf->blkSize + 1) * buf->numAllBlk)
53 | {
54 | if (*blkPtr == BLOCK_AVAILABLE)
55 | break;
56 | else
57 | blkPtr += buf->blkSize + 1;
58 | }
59 |
60 | *blkPtr = BLOCK_UNAVAILABLE;
61 | buf->numFreeBlk--;
62 | return blkPtr + 1;
63 | }
64 |
65 | void freeBlockInBuffer(unsigned char *blk, Buffer *buf)
66 | {
67 | *(blk - 1) = BLOCK_AVAILABLE;
68 | buf->numFreeBlk++;
69 | }
70 |
71 | int dropBlockOnDisk(unsigned int addr)
72 | {
73 | char filename[40];
74 |
75 | sprintf(filename, "%d.blk", addr);
76 |
77 | if (remove(filename) == -1)
78 | {
79 | perror("Dropping Block Fails!\n");
80 | return -1;
81 | }
82 |
83 | return 0;
84 | }
85 |
86 | unsigned char *readBlockFromDisk(unsigned int addr, Buffer *buf)
87 | {
88 | char filename[40];
89 | unsigned char *blkPtr, *bytePtr;
90 | char ch;
91 |
92 | if (buf->numFreeBlk == 0)
93 | {
94 | perror("Buffer Overflows!\n");
95 | return NULL;
96 | }
97 |
98 | blkPtr = buf->data;
99 |
100 | while (blkPtr < buf->data + (buf->blkSize + 1) * buf->numAllBlk)
101 | {
102 | if (*blkPtr == BLOCK_AVAILABLE)
103 | break;
104 | else
105 | blkPtr += buf->blkSize + 1;
106 | }
107 |
108 | sprintf(filename, "%d.blk", addr);
109 | FILE *fp = fopen(filename, "rb");
110 |
111 | if (!fp)
112 | {
113 | perror("Reading Block Failed!\n");
114 | return NULL;
115 | }
116 |
117 | *blkPtr = BLOCK_UNAVAILABLE;
118 | blkPtr++;
119 | bytePtr = blkPtr;
120 |
121 | while (bytePtr < blkPtr + buf->blkSize)
122 | {
123 | ch = fgetc(fp);
124 | *bytePtr = ch;
125 | bytePtr++;
126 | }
127 |
128 | fclose(fp);
129 | buf->numFreeBlk--;
130 | buf->numIO++;
131 | return blkPtr;
132 | }
133 |
134 | int writeBlockToDisk(unsigned char *blkPtr, unsigned int addr, Buffer *buf)
135 | {
136 | char filename[40];
137 | unsigned char *bytePtr;
138 |
139 | sprintf(filename, "%d.blk", addr);
140 | FILE *fp = fopen(filename, "wb");
141 |
142 | if (!fp)
143 | {
144 | perror("Writing Block Failed!\n");
145 | return -1;
146 | }
147 |
148 | for (bytePtr = blkPtr; bytePtr < blkPtr + buf->blkSize; bytePtr++)
149 | fputc((int)(*bytePtr), fp);
150 |
151 | fclose(fp);
152 | *(blkPtr - 1) = BLOCK_AVAILABLE;
153 | buf->numFreeBlk++;
154 | buf->numIO++;
155 | return 0;
156 | }
157 |
--------------------------------------------------------------------------------
/template.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,a4paper]{article}
2 | % 使用12pt(对应于中文的小四号字)
3 | % \usepackage{xeCJK}
4 | % \setmainfont{Times New Roman}
5 | % \setCJKmainfont[BoldFont=Hei]{Hei}
6 | \usepackage{ctex}
7 | \usepackage{geometry} %设置页边距的宏包
8 | \usepackage{titlesec} %设置页眉页脚的宏包
9 | \usepackage{amssymb}
10 | \usepackage{amsmath}
11 | \geometry{left=3.17cm,right=3.17cm,top=2.54cm,bottom=2.54cm} %设置 上、左、下、右 页边距
12 | \begin{document}
13 | \newpagestyle{main}{
14 | \sethead{哈尔滨工业大学}{数据库系统\_第一次作业}{1160300314 朱明彦} %设置页眉
15 | % \setfoot{左页脚}{中页脚}{右页脚} %设置页脚,可以在页脚添加 \thepage 显示页数
16 | \setfoot{}{}{\thepage}
17 | \headrule % 添加页眉的下划线
18 | % \footrule %添加页脚的下划线
19 | }
20 | \pagestyle{main} %使用该style
21 |
22 | % \setlength{\baselineskip}{15.6pt}
23 | \setlength{\parskip}{0pt}
24 | \renewcommand{\baselinestretch}{1.5}
25 |
26 | \paragraph{一、}
27 | \subparagraph{1. A} 可以举出以下反例
28 |
29 | \begin{minipage}{\textwidth}
30 | \begin{minipage}[t]{0.35\textwidth}
31 | \centering
32 | \makeatletter\def\@captype{table}\makeatother\caption{R}
33 | \begin{tabular}{c|c}
34 | \hline
35 | A & F \\ \hline
36 | 1 & 2 \\
37 | 3 & 4 \\
38 | \hline
39 | \end{tabular}
40 | \end{minipage}
41 | \begin{minipage}[t]{0.35\textwidth}
42 | \centering
43 | \makeatletter\def\@captype{table}\makeatother\caption{S}
44 | \begin{tabular}{c|c}
45 | \hline
46 | A & F \\ \hline
47 | 2 & 2 \\
48 | 3 & 2 \\
49 | \hline
50 | \end{tabular}
51 |
52 | \end{minipage}
53 |
54 | \end{minipage}
55 | \vspace{0.5cm}\\
56 | 可以看到,对于左式$\Pi_F(R_1 \cap R_2) = \varnothing$;而对于右式$\Pi_F(R_1) \cap \Pi_F(R_2) = \{2\}$。因而A错误。
57 |
58 | \subparagraph{2. A} 对于R$\times$S的前r列为R的一个元组,后s列为S的一个元组,故原来比较中使用的为R的第i列和S的第j列,此处应该换为R$\times$S的第i列和第j+r列。
59 | \paragraph{二、}
60 | \subparagraph{1.} $\Pi_{SNO, PNO}(SPJ) \div \Pi_{SNO}(\sigma_{CITY = LONDON}(S))$
61 | \subparagraph{2.} $\Pi_{PNO}(SPJ \Join S \Join J)$
62 | \subparagraph{3.} $\Pi_{JNAME}(\sigma_{SNO = S1}(SPJ) \Join J)$
63 | \subparagraph{4.} $\Pi_{JNAME}((SPJ \Join J) \Join (\Pi_{PNO}(\sigma_{COLOR = red}(P))))$
64 | \subparagraph{5.} $\Pi_{JNAME, PNO}(SPJ \Join J) \div \Pi_{PNO}(P)$
65 | \subparagraph{6.} $\Pi_{SNAME, PNO}(SPJ \Join S) \div \sigma_{PNO = P1 \lor PNO = P2}(\Pi_{PNO}(P))$
66 | \subparagraph{7.} $\Pi_{PNAME}(P \Join \Pi_{COLOR}(\sigma_{PNAME = "TV"}(P)))$
67 |
68 | \paragraph{三、}
69 | \subparagraph{(1)} $\{t | \exists u \in R \land t[B] = u[B] \land t[C] = u[C]\}$
70 | \subparagraph{(2)} $\{t | t \in R \land t[B] > t[C]\}$
71 | \subparagraph{(3)} $\{t | t \in R \lor t \in S\}$
72 | \subparagraph{(4)} $\{t | t \in R \land t \in S\}$
73 | \subparagraph{(5)} $\{t | t \in R \land t \notin S\}$
74 | \subparagraph{(6)} $\{t | \exists r \in R \land \exists s \in S \land r[B] = s[B] \land t[A] = r[A] \land t[B] = r[B] \land t[C] = s[C]\}$
75 | \subparagraph{(7)}
76 | \begin{equation*}
77 | \begin{split}
78 | & \{t | t \in \{u | \exists r \in R \land u[A] = r[A] \land u[B] = r[B]\} \\
79 | & \land (\forall s \in \{v | \exists p \in S \land v[C] = p[C]\})(\exists r \in R \land r[A] = t[A] \land r[B] = t[B] \land s[C] = r[C])\}
80 | \end{split}
81 | \end{equation*}
82 |
83 | \paragraph{四、}
84 | \begin{itemize}
85 | \item 联系:限制在安全表达式范围内的元组关系演算,限制在安全表达式范围内的域关系演算以及关系代数的表达能力等价。
86 | \item 区别:
87 | \begin{itemize}
88 | \item \textbf{关系代数}是一种抽象的查询语言,它用对关系的运算来表达查询;并且有限关系上的关系代数操作结果都不会导致无限关系和无穷验证,因此关系代数系统是安全的。
89 | \item \textbf{元组关系演算}是非过程化的查询语言,只描述所需信息,而不给出获得该信息的具体过程;并且元组关系演算系统不是安全的。
90 | \item \textbf{域关系演算}是另一种关系演算的另一种形式,使用从属性域中取值的域变量,而不是整个元组的值;并且关系演算系统也不是安全的。
91 | \end{itemize}
92 | \end{itemize}
93 |
94 |
95 | \end{document}
--------------------------------------------------------------------------------
/homework_1/homewoke_1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,a4paper]{article}
2 | % 使用12pt(对应于中文的小四号字)
3 | % \usepackage{xeCJK}
4 | % \setmainfont{Times New Roman}
5 | % \setCJKmainfont[BoldFont=Hei]{Hei}
6 | \usepackage{ctex}
7 | \usepackage{geometry} %设置页边距的宏包
8 | \usepackage{titlesec} %设置页眉页脚的宏包
9 | \usepackage{amssymb}
10 | \usepackage{amsmath}
11 | \geometry{left=3.17cm,right=3.17cm,top=2.54cm,bottom=2.54cm} %设置 上、左、下、右 页边距
12 | \begin{document}
13 | \newpagestyle{main}{
14 | \sethead{哈尔滨工业大学}{数据库系统\_第一次作业}{1160300314 朱明彦} %设置页眉
15 | % \setfoot{左页脚}{中页脚}{右页脚} %设置页脚,可以在页脚添加 \thepage 显示页数
16 | \setfoot{}{}{\thepage}
17 | \headrule % 添加页眉的下划线
18 | % \footrule %添加页脚的下划线
19 | }
20 | \pagestyle{main} %使用该style
21 |
22 | % \setlength{\baselineskip}{15.6pt}
23 | \setlength{\parskip}{0pt}
24 | \renewcommand{\baselinestretch}{1.5}
25 |
26 | \paragraph{一、}
27 | \subparagraph{1. A} 可以举出以下反例
28 |
29 | \begin{minipage}{\textwidth}
30 | \begin{minipage}[t]{0.35\textwidth}
31 | \centering
32 | \makeatletter\def\@captype{table}\makeatother\caption{R}
33 | \begin{tabular}{c|c}
34 | \hline
35 | A & F \\ \hline
36 | 1 & 2 \\
37 | 3 & 4 \\
38 | \hline
39 | \end{tabular}
40 | \end{minipage}
41 | \begin{minipage}[t]{0.35\textwidth}
42 | \centering
43 | \makeatletter\def\@captype{table}\makeatother\caption{S}
44 | \begin{tabular}{c|c}
45 | \hline
46 | A & F \\ \hline
47 | 2 & 2 \\
48 | 3 & 2 \\
49 | \hline
50 | \end{tabular}
51 |
52 | \end{minipage}
53 |
54 | \end{minipage}
55 | \vspace{0.5cm}\\
56 | 可以看到,对于左式$\Pi_F(R_1 \cap R_2) = \varnothing$;而对于右式$\Pi_F(R_1) \cap \Pi_F(R_2) = \{2\}$。因而A错误。
57 |
58 | \subparagraph{2. A} 对于R$\times$S的前r列为R的一个元组,后s列为S的一个元组,故原来比较中使用的为R的第i列和S的第j列,此处应该换为R$\times$S的第i列和第j+r列。
59 | \paragraph{二、}
60 | \subparagraph{1.} $\Pi_{SNO, PNO}(SPJ) \div \Pi_{SNO}(\sigma_{CITY = LONDON}(S))$
61 | \subparagraph{2.} $\Pi_{PNO}(SPJ \Join S \Join J)$
62 | \subparagraph{3.} $\Pi_{JNAME}(\sigma_{SNO = S1}(SPJ) \Join J)$
63 | \subparagraph{4.} $\Pi_{JNAME}((SPJ \Join J) \Join (\Pi_{PNO}(\sigma_{COLOR = red}(P))))$
64 | \subparagraph{5.} $\Pi_{JNAME, PNO}(SPJ \Join J) \div \Pi_{PNO}(P)$
65 | \subparagraph{6.} $\Pi_{SNAME, PNO}(SPJ \Join S) \div \sigma_{PNO = P1 \lor PNO = P2}(\Pi_{PNO}(P))$
66 | \subparagraph{7.} $\Pi_{PNAME}(P \Join \Pi_{COLOR}(\sigma_{PNAME = "TV"}(P)))$
67 |
68 | \paragraph{三、}
69 | \subparagraph{(1)} $\{t | \exists u \in R \land t[B] = u[B] \land t[C] = u[C]\}$
70 | \subparagraph{(2)} $\{t | t \in R \land t[B] > t[C]\}$
71 | \subparagraph{(3)} $\{t | t \in R \lor t \in S\}$
72 | \subparagraph{(4)} $\{t | t \in R \land t \in S\}$
73 | \subparagraph{(5)} $\{t | t \in R \land t \notin S\}$
74 | \subparagraph{(6)} $\{t | \exists r \in R \land \exists s \in S \land r[B] = s[B] \land t[A] = r[A] \land t[B] = r[B] \land t[C] = s[C]\}$
75 | \subparagraph{(7)}
76 | \begin{equation*}
77 | \begin{split}
78 | & \{t | t \in \{u | \exists r \in R \land u[A] = r[A] \land u[B] = r[B]\} \\
79 | & \land (\forall s \in \{v | \exists p \in S \land v[C] = p[C]\})(\exists r \in R \land r[A] = t[A] \land r[B] = t[B] \land s[C] = r[C])\}
80 | \end{split}
81 | \end{equation*}
82 |
83 | \paragraph{四、}
84 | \begin{itemize}
85 | \item 联系:限制在安全表达式范围内的元组关系演算,限制在安全表达式范围内的域关系演算以及关系代数的表达能力等价。
86 | \item 区别:
87 | \begin{itemize}
88 | \item \textbf{关系代数}是一种抽象的查询语言,它用对关系的运算来表达查询;并且有限关系上的关系代数操作结果都不会导致无限关系和无穷验证,因此关系代数系统是安全的。
89 | \item \textbf{元组关系演算}是非过程化的查询语言,只描述所需信息,而不给出获得该信息的具体过程;并且元组关系演算系统不是安全的。
90 | \item \textbf{域关系演算}是另一种关系演算的另一种形式,使用从属性域中取值的域变量,而不是整个元组的值;并且关系演算系统也不是安全的。
91 | \end{itemize}
92 | \end{itemize}
93 |
94 |
95 | \end{document}
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/employees.txt:
--------------------------------------------------------------------------------
1 | 彭龙全 513436200003186558 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 7836 230103199507129080 7
2 | 倪山 513436200003187059 大民兴街9号 1686 42050519910712845X 4
3 | 周世华 513436200003188211 哈尔滨市道里区抚利街与抚顺街交会处 1529 350205199507128104 9
4 | 王仪叶 513436200003189150 哈尔滨市道里区抚利街与抚顺街交会处 2370 310105199107127599 1
5 | 于凝刚 513436200003189273 哈尔滨市道里区顾新路295号 5948 310105199107129279 4
6 | 太叔玛 51343620000318945X 顾新路396号 10922 51343620000318945X 1
7 | 长孙韦 513436200003188393 顾新路396号 1474 450302198712187539 4
8 | 裘世 513436200003189492 黑龙江省哈尔滨市道里区安阳路1号 9311 45030219871218889X 2
9 | 封明 513436200003188297 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 9526 450302198712186712 2
10 | 何强辉 513436200003188676 哈尔滨市南岗区学府三道街27号 10826 23010319950712882X 1
11 | 阙亚 513436200003189353 哈尔滨市道里区抚利街与抚顺街交会处 8729 350205199507129844 5
12 | 霍紫瑾 513436200003186996 哈尔滨市道里区河松街219号 7422 410303198712187634 5
13 | 宗勤 513436200003188916 黑龙江省哈尔滨市道里区安阳路1号 4317 310105199107126756 1
14 | 关琴 230103199507126541 哈尔滨市道里区顾新路295号 5084 350205199507129844 7
15 | 齐娟 230103199507129080 红领巾街02-2号 6960 45030219871218889X 9
16 | 马豪 230103199507128803 红领巾街02-2号 5589 513436200003188297 1
17 | 丁江毓 230103199507129347 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 5065 23010319950712882X 5
18 | 柏蝶平 230103199507126568 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 2960 450302198712187539 1
19 | 溥羽娴 230103199507129726 哈尔滨市南岗区松花江街139号 5161 310105199107126131 2
20 | 桑桂 230103199507128483 红领巾街02-2号 1790 513436200003188393 3
21 | 裘启竹 230103199507129785 哈尔滨市道里区顾新路295号 6977 450302198712188195 5
22 | 姜策春 23010319950712882X 大民兴街9号 5594 350205199507128104 8
23 | 石程 230103199507127560 哈尔滨市南岗区学府三道街27号 7281 350205199507128921 7
24 | 习贝 230103199507129427 哈尔滨市南岗区松花江街139号 6792 420505199107129292 3
25 | 裴纯晶 230103199507128360 黑龙江省哈尔滨市道里区安阳路1号 1290 410303198712187917 7
26 | 叶中晶 230103199507128205 黑龙江省哈尔滨市道里区安阳路1号 8482 410303198712188477 2
27 | 耿伊 35020519950712754X 黑龙江省哈尔滨市道里区安阳路1号 1902 450302198712187539 7
28 | 赫连友 350205199507127507 哈尔滨市道里区抚利街与抚顺街交会处 4708 230103199507129726 4
29 | 庾政 350205199507129844 红领巾街02-2号 4280 410303198712187415 2
30 | 云学彩 350205199507127769 哈尔滨市道里区抚利街与抚顺街交会处 8894 513436200003187059 9
31 | 庄红永 350205199507129043 顾新路396号 7054 513436200003188297 3
32 | 荀露 350205199507128729 哈尔滨市南岗区学府三道街27号 5188 350205199507127507 9
33 | 冉有 350205199507127582 南岗区北京街100号 1575 513436200003188211 9
34 | 景兴绍 350205199507128921 哈尔滨市道里区抚利街与抚顺街交会处 9353 410303198712189170 3
35 | 郭恒月 350205199507128366 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 1174 350205199507127101 2
36 | 路言良 350205199507129908 顾新路396号 8694 410303198712187650 7
37 | 谈怡奇 350205199507126387 顾新路396号 1133 410303198712188477 5
38 | 周淑言 350205199507128104 哈尔滨市道里区顾新路295号 1844 350205199507126387 6
39 | 闻莲谦 350205199507127101 哈尔滨市道里区抚利街与抚顺街交会处 10444 35020519950712754X 2
40 | 荆和炎 42050519910712845X 哈尔滨市道里区河松街219号 3015 51343620000318945X 3
41 | 伊芬 420505199107129292 哈尔滨市道里区顾新路295号 1543 420505199107128513 2
42 | 穆贞 420505199107127078 顾新路396号 4274 23010319950712882X 5
43 | 江瑞 420505199107127334 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 3449 230103199507128803 3
44 | 葛邦泰 420505199107127414 哈尔滨市道里区河松街219号 6059 45030219871218889X 4
45 | 齐政策 420505199107129532 哈尔滨市南岗区松花江街139号 8950 310105199107126131 6
46 | 幸功 420505199107126550 红领巾街02-2号 5898 410303198712187650 8
47 | 沈羽 420505199107127393 红领巾街02-2号 4727 230103199507128483 5
48 | 阮育轮 420505199107128097 哈尔滨市道里区顾新路295号 6994 42050519910712845X 5
49 | 屈烟纨 420505199107128353 哈尔滨市道里区抚利街与抚顺街交会处 3372 41030319871218605X 6
50 | 师强 420505199107128513 哈尔滨市南岗区学府三道街27号 8733 410303198712188899 4
51 | 杨以 420505199107127772 哈尔滨市道里区顾新路295号 5771 420505199107128353 4
52 | 屈广 310105199107127898 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 9501 410303198712187415 5
53 | 封鸿馨 310105199107126377 黑龙江省哈尔滨市道里区安阳路1号 8256 350205199507128729 4
54 | 姜梅 310105199107128372 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 5855 230103199507129080 7
55 | 欧胜 310105199107127732 哈尔滨市道里区河松街219号 9127 410303198712187650 2
56 | 司马善 310105199107127599 哈尔滨市道里区河松街219号 2342 310105199107129439 4
57 | 池恒 310105199107126756 南岗区北京街100号 7875 310105199107126377 5
58 | 戴宏蝶 310105199107129279 哈尔滨市南岗区松花江街139号 9001 35020519950712754X 1
59 | 申屠影 310105199107126510 南岗区北京街100号 1607 310105199107126115 3
60 | 马军 310105199107129914 哈尔滨市道里区顾新路295号 2805 450302198712189673 1
61 | 阙明韦 310105199107126537 顾新路396号 2374 45030219871218889X 7
62 | 孟祥霭 310105199107129439 哈尔滨市道里区河松街219号 5253 410303198712188274 4
63 | 管聪宇 310105199107126131 哈尔滨市道里区河松街219号 6493 410303198712189170 3
64 | 禄艳珠 310105199107126115 哈尔滨市南岗区学府三道街27号 10151 420505199107129532 7
65 | 桑锦唯 450302198712186632 大民兴街9号 3682 410303198712188477 9
66 | 唐玛 450302198712188734 哈尔滨市道里区河松街219号 6058 230103199507128205 1
67 | 魏裕 450302198712187870 顾新路396号 4580 310105199107126131 4
68 | 姚咏咏 450302198712188013 黑龙江省哈尔滨市道里区安阳路1号 8242 51343620000318945X 8
69 | 惠红纨 450302198712188195 哈尔滨市道里区抚利街与抚顺街交会处 7386 350205199507129043 9
70 | 太叔滢 450302198712187539 黑龙江省哈尔滨市道里区安阳路1号 1247 230103199507127560 7
71 | 沈真 45030219871218889X 哈尔滨市道里区顾新路295号 3718 41030319871218605X 8
72 | 怀彦翰 450302198712187539 哈尔滨市道里区顾新路295号 1164 513436200003186558 3
73 | 仲孙言 450302198712186712 哈尔滨市南岗区松花江街139号 9015 450302198712189032 2
74 | 缪露 450302198712189673 哈尔滨市南岗区松花江街139号 9525 410303198712186359 2
75 | 雷致 450302198712189032 哈尔滨市道里区顾新路295号 3650 350205199507127507 2
76 | 韩良俊 450302198712188873 南岗区北京街100号 8915 420505199107127334 2
77 | 童洋顺 450302198712188558 哈尔滨市道里区河松街219号 6888 350205199507127582 4
78 | 路恒萍 410303198712188530 大民兴街9号 4980 41030319871218779X 2
79 | 夏侯行 410303198712188477 黑龙江省哈尔滨市南岗区和兴十一道街28-1号 4261 513436200003189353 7
80 | 上官唯 410303198712187917 哈尔滨市道里区抚利街与抚顺街交会处 6125 310105199107129439 3
81 | 张红 410303198712187415 哈尔滨市南岗区松花江街139号 8446 230103199507128803 8
82 | 苗栋发 410303198712187650 哈尔滨市南岗区学府三道街27号 10415 450302198712189673 5
83 | 易倩茗 410303198712189672 哈尔滨市南岗区学府三道街27号 6475 513436200003186558 6
84 | 卓锦婕 410303198712189170 哈尔滨市道里区顾新路295号 8952 450302198712186632 2
85 | 云彩弘 410303198712188899 南岗区北京街100号 7721 310105199107129279 1
86 | 邵顺 410303198712188274 哈尔滨市南岗区松花江街139号 8858 513436200003188916 1
87 | 秦瑶 410303198712187634 南岗区北京街100号 9579 513436200003189273 7
88 | 骆瑞 41030319871218605X 哈尔滨市南岗区松花江街139号 10469 420505199107128353 4
89 | 姚香 41030319871218779X 哈尔滨市道里区河松街219号 8505 350205199507128921 3
90 | 瞿泰承 410303198712186359 哈尔滨市南岗区松花江街139号 3025 230103199507126568 8
91 |
--------------------------------------------------------------------------------
/lab_1/lab_1/source_file/work_on.txt:
--------------------------------------------------------------------------------
1 | 513436200003186558 P6 1
2 | 513436200003187059 P8 0
3 | 513436200003187059 P11 5
4 | 513436200003187059 P8 4
5 | 513436200003187059 P3 2
6 | 513436200003188211 P10 7
7 | 513436200003189150 P4 7
8 | 513436200003189150 P2 6
9 | 513436200003189150 P4 6
10 | 513436200003189273 P4 1
11 | 51343620000318945X P10 0
12 | 51343620000318945X P5 0
13 | 513436200003188393 P4 1
14 | 513436200003189492 P8 3
15 | 513436200003188297 P8 1
16 | 513436200003188297 P5 0
17 | 513436200003188676 P10 0
18 | 513436200003188676 P3 4
19 | 513436200003189353 P8 3
20 | 513436200003189353 P5 7
21 | 513436200003186996 P9 7
22 | 513436200003186996 P5 3
23 | 513436200003186996 P6 1
24 | 513436200003188916 P9 7
25 | 230103199507126541 P7 7
26 | 230103199507126541 P6 7
27 | 230103199507126541 P5 2
28 | 230103199507129080 P5 1
29 | 230103199507128803 P3 4
30 | 230103199507128803 P4 0
31 | 230103199507128803 P4 2
32 | 230103199507129347 P9 0
33 | 230103199507126568 P7 3
34 | 230103199507126568 P3 3
35 | 230103199507129726 P7 3
36 | 230103199507129726 P4 4
37 | 230103199507128483 P8 2
38 | 230103199507128483 P8 3
39 | 230103199507128483 P9 0
40 | 230103199507128483 P1 5
41 | 230103199507129785 P11 0
42 | 230103199507129785 P5 6
43 | 230103199507129785 P1 2
44 | 230103199507129785 P11 2
45 | 23010319950712882X P2 4
46 | 23010319950712882X P8 2
47 | 23010319950712882X P1 7
48 | 230103199507127560 P3 6
49 | 230103199507127560 P8 6
50 | 230103199507127560 P5 6
51 | 230103199507129427 P2 4
52 | 230103199507129427 P1 1
53 | 230103199507128360 P2 6
54 | 230103199507128360 P4 0
55 | 230103199507128360 P5 0
56 | 230103199507128360 P3 3
57 | 230103199507128205 P1 0
58 | 230103199507128205 P10 5
59 | 230103199507128205 P4 6
60 | 35020519950712754X P3 0
61 | 350205199507127507 P1 3
62 | 350205199507127507 P10 1
63 | 350205199507129844 P5 7
64 | 350205199507129844 P1 4
65 | 350205199507129844 P7 3
66 | 350205199507127769 P8 5
67 | 350205199507129043 P8 5
68 | 350205199507129043 P2 3
69 | 350205199507129043 P5 4
70 | 350205199507129043 P4 0
71 | 350205199507128729 P2 6
72 | 350205199507127582 P11 6
73 | 350205199507127582 P5 3
74 | 350205199507127582 P9 6
75 | 350205199507128921 P11 5
76 | 350205199507128366 P9 7
77 | 350205199507128366 P10 7
78 | 350205199507129908 P3 2
79 | 350205199507129908 P7 4
80 | 350205199507126387 P3 0
81 | 350205199507128104 P9 3
82 | 350205199507127101 P5 4
83 | 350205199507127101 P11 0
84 | 350205199507127101 P3 2
85 | 350205199507127101 P8 2
86 | 42050519910712845X P11 2
87 | 420505199107129292 P9 3
88 | 420505199107129292 P8 6
89 | 420505199107129292 P5 2
90 | 420505199107127078 P2 6
91 | 420505199107127334 P3 7
92 | 420505199107127414 P3 5
93 | 420505199107127414 P8 6
94 | 420505199107129532 P1 5
95 | 420505199107129532 P8 4
96 | 420505199107126550 P9 0
97 | 420505199107126550 P1 1
98 | 420505199107127393 P8 6
99 | 420505199107127393 P5 3
100 | 420505199107127393 P8 3
101 | 420505199107128097 P6 5
102 | 420505199107128097 P11 2
103 | 420505199107128097 P9 2
104 | 420505199107128097 P2 2
105 | 420505199107128353 P8 3
106 | 420505199107128353 P6 1
107 | 420505199107128353 P10 1
108 | 420505199107128513 P9 4
109 | 420505199107128513 P2 5
110 | 420505199107128513 P11 6
111 | 420505199107128513 P9 6
112 | 420505199107127772 P1 5
113 | 420505199107127772 P7 6
114 | 310105199107127898 P10 0
115 | 310105199107126377 P8 1
116 | 310105199107126377 P7 2
117 | 310105199107126377 P9 4
118 | 310105199107128372 P1 7
119 | 310105199107128372 P8 5
120 | 310105199107128372 P8 7
121 | 310105199107127732 P4 2
122 | 310105199107127599 P9 4
123 | 310105199107127599 P1 1
124 | 310105199107127599 P7 6
125 | 310105199107126756 P6 5
126 | 310105199107126756 P3 3
127 | 310105199107126756 P9 4
128 | 310105199107126756 P9 2
129 | 310105199107129279 P2 7
130 | 310105199107129279 P6 0
131 | 310105199107129279 P7 7
132 | 310105199107129279 P11 0
133 | 310105199107126510 P9 3
134 | 310105199107126510 P9 1
135 | 310105199107126510 P1 7
136 | 310105199107129914 P10 2
137 | 310105199107126537 P6 1
138 | 310105199107129439 P3 4
139 | 310105199107129439 P4 0
140 | 310105199107129439 P6 4
141 | 310105199107126131 P2 5
142 | 310105199107126131 P2 2
143 | 310105199107126115 P4 6
144 | 310105199107126115 P8 1
145 | 310105199107126115 P3 2
146 | 450302198712186632 P6 6
147 | 450302198712186632 P8 3
148 | 450302198712186632 P10 2
149 | 450302198712188734 P1 4
150 | 450302198712187870 P10 4
151 | 450302198712187870 P11 6
152 | 450302198712188013 P11 7
153 | 450302198712188013 P4 0
154 | 450302198712188195 P10 0
155 | 450302198712187539 P1 7
156 | 450302198712187539 P11 7
157 | 450302198712187539 P10 2
158 | 450302198712187539 P11 3
159 | 45030219871218889X P8 0
160 | 45030219871218889X P10 3
161 | 450302198712187539 P10 5
162 | 450302198712186712 P4 4
163 | 450302198712186712 P9 4
164 | 450302198712186712 P10 1
165 | 450302198712189673 P4 4
166 | 450302198712189032 P5 0
167 | 450302198712189032 P9 4
168 | 450302198712189032 P6 6
169 | 450302198712189032 P2 1
170 | 450302198712188873 P2 5
171 | 450302198712188873 P5 2
172 | 450302198712188558 P2 4
173 | 450302198712188558 P6 6
174 | 450302198712188558 P3 6
175 | 450302198712188558 P6 4
176 | 410303198712188530 P10 6
177 | 410303198712188530 P2 6
178 | 410303198712188530 P9 0
179 | 410303198712188530 P1 7
180 | 410303198712188477 P9 5
181 | 410303198712188477 P8 6
182 | 410303198712188477 P1 2
183 | 410303198712188477 P5 3
184 | 410303198712187917 P8 6
185 | 410303198712187917 P4 6
186 | 410303198712187415 P3 6
187 | 410303198712187415 P9 4
188 | 410303198712187415 P1 0
189 | 410303198712187650 P11 6
190 | 410303198712187650 P2 5
191 | 410303198712187650 P10 7
192 | 410303198712187650 P9 1
193 | 410303198712189672 P8 2
194 | 410303198712189672 P9 1
195 | 410303198712189672 P6 6
196 | 410303198712189672 P6 7
197 | 410303198712189170 P4 5
198 | 410303198712189170 P9 2
199 | 410303198712189170 P1 4
200 | 410303198712189170 P9 5
201 | 410303198712188899 P11 3
202 | 410303198712188899 P5 1
203 | 410303198712188899 P9 7
204 | 410303198712188274 P4 5
205 | 410303198712188274 P3 7
206 | 410303198712187634 P5 1
207 | 410303198712187634 P2 0
208 | 410303198712187634 P4 6
209 | 41030319871218605X P7 0
210 | 41030319871218779X P6 3
211 | 410303198712186359 P7 0
212 | 410303198712186359 P3 0
213 |
--------------------------------------------------------------------------------
/homework_6/homework_6.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt, a4paper]{article}
2 | % 使用12pt(对应于中文的小四号字)
3 | % \usepackage{xeCJK}
4 | % \setmainfont{Times New Roman}
5 | % \setCJKmainfont[BoldFont=Hei]{Hei}
6 | \usepackage{array, ragged2e, pst-node, pst-dbicons}
7 | \usepackage{ctex}
8 | \usepackage{geometry} %设置页边距的宏包
9 | \usepackage{titlesec} %设置页眉页脚的宏包
10 | \usepackage{amssymb}
11 | \usepackage{amsmath}
12 | \usepackage{tikz-er2}
13 | \usepackage{graphviz}
14 | \usepackage{minted}
15 | \usepackage[utf8]{inputenc}
16 | \usepackage{tikz}
17 | \usetikzlibrary{automata, positioning, arrows, shapes.geometric}
18 |
19 | \tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
20 | \tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
21 | \tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
22 | \tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
23 | \tikzstyle{arrow} = [thick,->,>=stealth]
24 | \newminted{text}{frame=lines, framesep=2mm}
25 | \newminted{python}{frame=lines, framesep=2mm, linenos}
26 | \geometry{left=3.17cm, right=3.17cm, top=2.54cm, bottom=2.54cm} %设置 上、左、下、右 页边距
27 | \begin{document}
28 | \newpagestyle{main}{
29 | \sethead{哈尔滨工业大学}{数据库系统\_第六次作业}{1160300314 朱明彦} %设置页眉
30 | % \setfoot{左页脚}{中页脚}{右页脚} %设置页脚, 可以在页脚添加 \thepage 显示页数
31 | \setfoot{}{}{\thepage}
32 | \headrule % 添加页眉的下划线
33 | % \footrule %添加页脚的下划线
34 | }
35 | \pagestyle{main} %使用该style
36 | \usetikzlibrary{positioning}
37 | \usetikzlibrary{shadows}
38 | \usetikzlibrary{arrows}
39 | \tikzstyle{every entity} = [top color=white, bottom color=blue!30,
40 | draw=blue!50!black!100, drop shadow]
41 | \tikzstyle{every weak entity} = [drop shadow={shadow xshift=.7ex,
42 | shadow yshift=-.7ex}]
43 | \tikzstyle{every attribute} = [top color=white, bottom color=yellow!20,
44 | draw=yellow, node distance=1cm, drop shadow]
45 | \tikzstyle{every relationship} = [top color=white, bottom color=red!20,
46 | draw=red!50!black!100, drop shadow]
47 | \tikzstyle{every isa} = [top color=white, bottom color=green!20,
48 | draw=green!50!black!100, drop shadow]
49 |
50 | % \setlength{\baselineskip}{15.6pt}
51 | % \setlength{\parskip}{0pt}
52 | \renewcommand{\baselinestretch}{1.5}
53 |
54 | \begin{enumerate}
55 | \item \begin{enumerate}
56 | \item \textbf{选择PlanA。}理由是,一般情况下优先做选择($\sigma$)操作可以减少用于连接元组的数量,进一步降低连接的代价。
57 | \item \textbf{是。}理由是,如果已知$R$和$S$在连接属性值$k$上的分布,并且二者没有交集。
58 | \end{enumerate}
59 | \item 可以画出原有调度的优先图如图\ref{fig:2},从图中可以看到在$0$和$2$中存在环路,所以\textbf{这不是一个冲突可串行化调度}。
60 | \begin{figure}[htb]
61 | \centering
62 | \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]
63 | \node[state] (q0) {$0$};
64 | \node[state, right of=q0] (q1) {$1$};
65 | \node[state, right of=q1] (q2) {$2$};
66 | \draw (q0) edge [bend right, above] (q2)
67 | (q2) edge [bend right, above] (q0)
68 | (q2) edge [bend right, above] (q1);
69 | \end{tikzpicture}
70 | \caption{第2题调度的优先图}
71 | \label{fig:2}
72 | \end{figure}
73 | \item 用两阶段锁保证题目2的调度冲突可并行化,\textbf{结果如表\ref{tab:3}所示}。
74 | \begin{table}[htb]
75 | \centering
76 | \begin{tabular}{l|l|l}
77 | T0 & T1 & T2 \\ \hline
78 | \textbf{LOCK-X(A)} & &\\
79 | r0(A) & & \\
80 | w0(A) & & \\
81 | \textbf{LOCK-X(B)}& & \\
82 | r0(B) & & \\
83 | w0(B) & & \\
84 | \textbf{UNLOCK(A)} & &\\
85 | & & \textbf{LOCK-X(A)}\\
86 | \textbf{UNLOCK(B)} & &\\
87 | & & w2(A) \\
88 | & & r2(A) \\
89 | & & \textbf{LOCK-X(B)}\\
90 | & & r2(B) \\
91 | & & W2(B) \\
92 | & & \textbf{UNLCOK(A)}\\
93 | &\textbf{LOCK-S(A)}& \\
94 | & & \textbf{UNLOCK(B)}\\
95 | & r1(A) & \\
96 | &\textbf{LOCK-S(B)} & \\
97 | & r1(B) & \\
98 | & \textbf{UNLOCK(A)} &\\
99 | & \textbf{UNLOCK(B)} &\\
100 | \end{tabular}
101 | \caption{使用两阶段锁保证调度的冲突可并行化}\label{tab:3}
102 | \end{table}
103 | \item \textbf{结果如表\ref{tab:4}所示},其中在T2执行完Write(A)时,由于TS(T2) $<$ R-ts(A),所以T2需要回滚。
104 | \begin{table}[htb]
105 | \centering
106 | \begin{tabular}{|l|l|l|l|l|l|}
107 | \hline
108 | T1 & T2 & W-ts(A) & R-ts(A) & W-ts(B) & R-ts(B) \\ \hline
109 | & Read(B); & & & \textbf{} & \textbf{TS(T2)} \\ \hline
110 | & B := B - 50; & & & \textbf{} & \textbf{TS(T2)} \\ \hline
111 | & Write(B); & & & \textbf{TS(T2)} & \textbf{TS(T2)} \\ \hline
112 | READ(B); & & & & \textbf{TS(T2)} & \textbf{TS(T1)} \\ \hline
113 | & READ(A); & & \textbf{TS(T2)} & \textbf{TS(T2)} & \textbf{TS(T1)} \\ \hline
114 | & A := A = 50; & & \textbf{TS(T2)} & \textbf{TS(T2)} & \textbf{TS(T1)} \\ \hline
115 | Read(A); & & & \textbf{TS(T1)} & \textbf{TS(T2)} & \textbf{TS(T1)} \\ \hline
116 | & Write(A); & 出现错误 & \textbf{TS(T1)} & \textbf{TS(T2)} & \textbf{TS(T1)} \\ \hline
117 | Display(A+B); & & & \textbf{TS(T1)} & \textbf{TS(T2)} & \textbf{TS(T1)} \\ \hline
118 | & Display(A+B); & & \textbf{TS(T1)} & \textbf{TS(T2)} & \textbf{TS(T1)} \\ \hline
119 | \end{tabular}
120 | \caption{时间戳}\label{tab:4}
121 | \end{table}
122 | \item \begin{enumerate}
123 | \item \textbf{结果如表\ref{tab:5_a}所示。}
124 | \begin{table}[htb]
125 | \centering
126 | \begin{tabular}{|l|l|}
127 | \hline
128 | 1 & \textbf{\textless{}T0,start\textgreater{}} \\ \hline
129 | 2 & \textless{}T0, A, 50, 70\textgreater{} \\ \hline
130 | 3 & \textbf{\textless{}T2,start\textgreater{}} \\ \hline
131 | 4 & \textless{}start checkpoint (T0, T2)\textgreater{} \\ \hline
132 | 5 & \textless{}end checkpoint\textgreater{} \\ \hline
133 | 6 & \textless{}T1, commit\textgreater{} \\ \hline
134 | 7 & \textbf{\textless{}T1, B, 30, 20\textgreater{}} \\ \hline
135 | 8 & \textless{}T1, commit\textgreater{} \\ \hline
136 | 9 & \textless{}T2, C, 35, 70\textgreater{} \\ \hline
137 | 10 & \textbf{\textless{}T3, start\textgreater{}} \\ \hline
138 | 11 & \textless{}T3, D, 15, 30\textgreater{} \\ \hline
139 | 12 & \textbf{\textless{}T2, commit\textgreater{}} \\ \hline
140 | \end{tabular}
141 | \caption{日志文件}\label{tab:5_a}
142 | \end{table}
143 | \item \textbf{T1和T2需要Redo,T3和T0需要Undo}。根据日志文件,在故障恢复时T1和T2已经提交,需要Redo;而T0和T3未提交故Undo,需要消除其影响。
144 | \item \textbf{需要增加,和},表明T0和T3在故障中终止未提交。
145 | \end{enumerate}
146 | \end{enumerate}
147 | \end{document}
--------------------------------------------------------------------------------
/lab_1/lab_1/src/Main.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.text.SimpleDateFormat;
3 | import java.util.*;
4 |
5 | class Employee {
6 | String ename, essn, address, super_ssn;
7 | int salary, dno;
8 |
9 | public Employee(String ename, String essn, String address, String super_ssn, int salary, int dno) {
10 | this.ename = ename;
11 | this.essn = essn;
12 | this.address = address;
13 | this.super_ssn = super_ssn;
14 | this.salary = salary;
15 | this.dno = dno;
16 | }
17 |
18 | @Override
19 | public String toString() {
20 | return ename + "\t" + essn + "\t" + address + "\t" + salary + "\t" + super_ssn + "\t" + dno;
21 | }
22 | }
23 |
24 | class Department {
25 | String dname, mgrssn, mgr_start_date;
26 | int dno;
27 |
28 | public Department(String dname, String mgrssn, String mgr_start_date, int dno) {
29 | this.dname = dname;
30 | this.mgrssn = mgrssn;
31 | this.mgr_start_date = mgr_start_date;
32 | this.dno = dno;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return dname + "\t" + dno + "\t" + mgrssn + "\t" + mgr_start_date;
38 | }
39 | }
40 |
41 | class Project {
42 | String pname, plocation;
43 | String pno;
44 | int dno;
45 |
46 | public Project(String pname, String plocation, String pno, int dno) {
47 | this.pname = pname;
48 | this.plocation = plocation;
49 | this.pno = pno;
50 | this.dno = dno;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return pname + "\t" + pno + "\t" + plocation + "\t" + dno;
56 | }
57 | }
58 |
59 | class Works_on {
60 | String essn;
61 | int hours;
62 | String pno;
63 |
64 | public Works_on(String essn, String pno, int hours) {
65 | this.essn = essn;
66 | this.pno = pno;
67 | this.hours = hours;
68 | }
69 |
70 | @Override
71 | public String toString() {
72 | return essn + "\t" + pno + "\t" + hours;
73 | }
74 | }
75 |
76 | public class Main {
77 | private static final int MAX_SALARY = 10000;
78 | private static final int BASE_SALARY = 1000;
79 | private static final int MAX_RELATIONS = 200;
80 |
81 | public static void main(String[] args) {
82 | Random random = new Random();
83 |
84 | List employeeList = new ArrayList<>();
85 | List locationList = new ArrayList<>();
86 | List departmentList = new ArrayList<>();
87 | List projectList = new ArrayList<>();
88 |
89 | try {
90 | // 获得项目列表
91 | BufferedReader bufferedReader = new BufferedReader(new FileReader("./source_file/department_name.txt"));
92 | String s;
93 | int count = 0;
94 | while ((s = bufferedReader.readLine()) != null) {
95 | departmentList.add(new Department(s, "", randomDateString(), ++count));
96 | }
97 | } catch (IOException e) {
98 | e.printStackTrace();
99 | }
100 |
101 | try {
102 | // 获得工程列表
103 | BufferedReader bufferedReader = new BufferedReader(new FileReader("./source_file/project_name_location.txt"));
104 | String s;
105 | int count = 0;
106 | while ((s = bufferedReader.readLine()) != null) {
107 | String[] values = s.split(" ");
108 | projectList.add(new Project(values[0].replace("_", " "), values[1], "P" + String.valueOf(++count), random.nextInt(departmentList.size()) + 1));
109 | }
110 | } catch (IOException e) {
111 | e.printStackTrace();
112 | }
113 |
114 | try {
115 | // 获得员工居住地址
116 | BufferedReader bufferedReader = new BufferedReader(new FileReader("./source_file/employee_location.txt"));
117 | String s;
118 | while ((s = bufferedReader.readLine()) != null) {
119 | locationList.add(s.replaceAll("\\s", ""));
120 | }
121 | } catch (IOException e) {
122 | e.printStackTrace();
123 | }
124 | try {
125 | // 获得员工姓名和身份证号
126 | BufferedReader bufferedReader = new BufferedReader(new FileReader("./source_file/employee_id.txt"));
127 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("./source_file/employees.txt"));
128 |
129 | String s;
130 | while ((s = bufferedReader.readLine()) != null) {
131 | String[] values = s.split(" ");
132 | int address = random.nextInt(locationList.size());
133 | employeeList.add(new Employee(values[0], values[1].replaceAll("\\s", ""), locationList.get(address)
134 | , "", random.nextInt(MAX_SALARY) + BASE_SALARY, random.nextInt(departmentList.size()) + 1));
135 |
136 | }
137 | bufferedWriter.close();
138 | } catch (IOException e) {
139 | e.printStackTrace();
140 | }
141 | for (Employee employee : employeeList) {
142 | int leader = random.nextInt(employeeList.size());
143 | employee.super_ssn = employeeList.get(leader).essn;
144 | }
145 |
146 | for (Department department : departmentList) {
147 | int leader = random.nextInt(employeeList.size());
148 | department.mgrssn = employeeList.get(leader).super_ssn;
149 | }
150 |
151 |
152 | List works_ons = new ArrayList<>();
153 | for (Employee employee : employeeList) {
154 | int projects_person = random.nextInt(4) + 1;
155 | for (int i = 0; i < projects_person; i++) {
156 | // 利用PRIMARY KEY 删除重复
157 | int hours = random.nextInt(8);
158 | int pid = random.nextInt(projectList.size());
159 | works_ons.add(new Works_on(employee.essn, projectList.get(pid).pno, hours));
160 | }
161 | }
162 |
163 | try {
164 | BufferedWriter employeeWriter = new BufferedWriter(new FileWriter("./source_file/employees.txt"));
165 | for (Employee employee : employeeList)
166 | employeeWriter.write(employee.toString() + "\n");
167 | employeeWriter.close();
168 |
169 | BufferedWriter departmentWriter = new BufferedWriter(new FileWriter("./source_file/departments.txt"));
170 | for (Department department : departmentList)
171 | departmentWriter.write(department.toString() + "\n");
172 | departmentWriter.close();
173 |
174 | BufferedWriter projectWriter = new BufferedWriter(new FileWriter("./source_file/projects.txt"));
175 | for (Project project : projectList)
176 | projectWriter.write(project.toString() + "\n");
177 | projectWriter.close();
178 |
179 | BufferedWriter work_onWriter = new BufferedWriter(new FileWriter("./source_file/work_on.txt"));
180 | for (Works_on works_on : works_ons)
181 | work_onWriter.write(works_on.toString() + "\n");
182 | work_onWriter.close();
183 | } catch (IOException e) {
184 | e.printStackTrace();
185 | }
186 | }
187 |
188 | private static String randomDateString() {
189 | Random rand = new Random();
190 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
191 | Calendar cal = Calendar.getInstance();
192 | cal.set(2004, 0, 1);
193 | long start = cal.getTimeInMillis();
194 | cal.set(2016, 0, 1);
195 | long end = cal.getTimeInMillis();
196 | Date d = new Date(start + (long) (rand.nextDouble() * (end - start)));
197 | return format.format(d);
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Core latex/pdflatex auxiliary files:
2 | *.aux
3 | *.lof
4 | *.log
5 | *.lot
6 | *.fls
7 | *.out
8 | *.toc
9 | *.fmt
10 | *.fot
11 | *.cb
12 | *.cb2
13 | .*.lb
14 |
15 | ## Intermediate documents:
16 | *.dvi
17 | *.xdv
18 | *-converted-to.*
19 | # these rules might exclude image files for figures etc.
20 | # *.ps
21 | # *.eps
22 | # *.pdf
23 |
24 | ## Generated if empty string is given at "Please type another file name for output:"
25 | .pdf
26 |
27 | ## Bibliography auxiliary files (bibtex/biblatex/biber):
28 | *.bbl
29 | *.bcf
30 | *.blg
31 | *-blx.aux
32 | *-blx.bib
33 | *.run.xml
34 |
35 | ## Build tool auxiliary files:
36 | *.fdb_latexmk
37 | *.synctex
38 | *.synctex(busy)
39 | *.synctex.gz
40 | *.synctex.gz(busy)
41 | *.pdfsync
42 |
43 | ## Auxiliary and intermediate files from other packages:
44 | # algorithms
45 | *.alg
46 | *.loa
47 |
48 | # achemso
49 | acs-*.bib
50 |
51 | # amsthm
52 | *.thm
53 |
54 | # beamer
55 | *.nav
56 | *.pre
57 | *.snm
58 | *.vrb
59 |
60 | # changes
61 | *.soc
62 |
63 | # cprotect
64 | *.cpt
65 |
66 | # elsarticle (documentclass of Elsevier journals)
67 | *.spl
68 |
69 | # endnotes
70 | *.ent
71 |
72 | # fixme
73 | *.lox
74 |
75 | # feynmf/feynmp
76 | *.mf
77 | *.mp
78 | *.t[1-9]
79 | *.t[1-9][0-9]
80 | *.tfm
81 |
82 | #(r)(e)ledmac/(r)(e)ledpar
83 | *.end
84 | *.?end
85 | *.[1-9]
86 | *.[1-9][0-9]
87 | *.[1-9][0-9][0-9]
88 | *.[1-9]R
89 | *.[1-9][0-9]R
90 | *.[1-9][0-9][0-9]R
91 | *.eledsec[1-9]
92 | *.eledsec[1-9]R
93 | *.eledsec[1-9][0-9]
94 | *.eledsec[1-9][0-9]R
95 | *.eledsec[1-9][0-9][0-9]
96 | *.eledsec[1-9][0-9][0-9]R
97 |
98 | # glossaries
99 | *.acn
100 | *.acr
101 | *.glg
102 | *.glo
103 | *.gls
104 | *.glsdefs
105 |
106 | # gnuplottex
107 | *-gnuplottex-*
108 |
109 | # gregoriotex
110 | *.gaux
111 | *.gtex
112 |
113 | # htlatex
114 | *.4ct
115 | *.4tc
116 | *.idv
117 | *.lg
118 | *.trc
119 | *.xref
120 |
121 | # hyperref
122 | *.brf
123 |
124 | # knitr
125 | *-concordance.tex
126 | # TODO Comment the next line if you want to keep your tikz graphics files
127 | *.tikz
128 | *-tikzDictionary
129 |
130 | # listings
131 | *.lol
132 |
133 | # makeidx
134 | *.idx
135 | *.ilg
136 | *.ind
137 | *.ist
138 |
139 | # minitoc
140 | *.maf
141 | *.mlf
142 | *.mlt
143 | *.mtc[0-9]*
144 | *.slf[0-9]*
145 | *.slt[0-9]*
146 | *.stc[0-9]*
147 |
148 | # minted
149 | _minted*
150 | *.pyg
151 |
152 | # morewrites
153 | *.mw
154 |
155 | # nomencl
156 | *.nlg
157 | *.nlo
158 | *.nls
159 |
160 | # pax
161 | *.pax
162 |
163 | # pdfpcnotes
164 | *.pdfpc
165 |
166 | # sagetex
167 | *.sagetex.sage
168 | *.sagetex.py
169 | *.sagetex.scmd
170 |
171 | # scrwfile
172 | *.wrt
173 |
174 | # sympy
175 | *.sout
176 | *.sympy
177 | sympy-plots-for-*.tex/
178 |
179 | # pdfcomment
180 | *.upa
181 | *.upb
182 |
183 | # pythontex
184 | *.pytxcode
185 | pythontex-files-*/
186 |
187 | # thmtools
188 | *.loe
189 |
190 | # TikZ & PGF
191 | *.dpth
192 | *.md5
193 | *.auxlock
194 |
195 | # todonotes
196 | *.tdo
197 |
198 | # easy-todo
199 | *.lod
200 |
201 | # xmpincl
202 | *.xmpi
203 |
204 | # xindy
205 | *.xdy
206 |
207 | # xypic precompiled matrices
208 | *.xyc
209 |
210 | # endfloat
211 | *.ttt
212 | *.fff
213 |
214 | # Latexian
215 | TSWLatexianTemp*
216 |
217 | ## Editors:
218 | # WinEdt
219 | *.bak
220 | *.sav
221 |
222 | # Texpad
223 | .texpadtmp
224 |
225 | # Kile
226 | *.backup
227 |
228 | # KBibTeX
229 | *~[0-9]*
230 |
231 | # auto folder when using emacs and auctex
232 | ./auto/*
233 | *.el
234 |
235 | # expex forward references with \gathertags
236 | *-tags.tex
237 |
238 | # standalone packages
239 | *.sta
240 |
241 | # generated if using elsarticle.cls
242 | *.spl
243 |
244 | # Package Files #
245 | *.jar
246 | *.war
247 | *.nar
248 | *.ear
249 | *.zip
250 | *.tar.gz
251 | *.rar
252 |
253 | # Compiled class file
254 | *.class
255 |
256 | # Log file
257 | *.log
258 |
259 | ### Gradle Files ###
260 | .gradle
261 | /build/
262 | !gradle/wrapper/gradle-wrapper.jar
263 |
264 | ### IntelliJ IDEA ###
265 | .idea
266 | *.iws
267 | *.iml
268 | *.ipr
269 | /out/
270 |
271 |
272 | # Created by https://www.gitignore.io/api/c,c++,cmake
273 | # Edit at https://www.gitignore.io/?templates=c,c++,cmake
274 |
275 | ### C ###
276 | # Prerequisites
277 | *.d
278 |
279 | # Object files
280 | *.o
281 | *.ko
282 | *.obj
283 | *.elf
284 |
285 | # Linker output
286 | *.ilk
287 | *.map
288 | *.exp
289 |
290 | # Precompiled Headers
291 | *.gch
292 | *.pch
293 |
294 | # Libraries
295 | *.lib
296 | *.a
297 | *.la
298 | *.lo
299 |
300 | # Shared objects (inc. Windows DLLs)
301 | *.dll
302 | *.so
303 | *.so.*
304 | *.dylib
305 |
306 | # Executables
307 | *.exe
308 | *.out
309 | *.app
310 | *.i*86
311 | *.x86_64
312 | *.hex
313 |
314 | # Debug files
315 | *.dSYM/
316 | *.su
317 | *.idb
318 | *.pdb
319 |
320 | # Kernel Module Compile Results
321 | *.mod*
322 | *.cmd
323 | .tmp_versions/
324 | modules.order
325 | Module.symvers
326 | Mkfile.old
327 | dkms.conf
328 |
329 | ### C++ ###
330 | # Prerequisites
331 |
332 | # Compiled Object files
333 | *.slo
334 |
335 | # Precompiled Headers
336 |
337 | # Compiled Dynamic libraries
338 |
339 | # Fortran module files
340 | *.mod
341 | *.smod
342 |
343 | # Compiled Static libraries
344 | *.lai
345 |
346 | # Executables
347 |
348 | ### CMake ###
349 | CMakeLists.txt.user
350 | CMakeCache.txt
351 | CMakeFiles
352 | CMakeScripts
353 | Testing
354 | Makefile
355 | cmake_install.cmake
356 | install_manifest.txt
357 | compile_commands.json
358 | CTestTestfile.cmake
359 | _deps
360 |
361 | ### CMake Patch ###
362 | # External projects
363 | *-prefix/
364 |
365 | # End of https://www.gitignore.io/api/c,c++,cmake
366 |
367 |
368 | # Created by https://www.gitignore.io/api/clion
369 | # Edit at https://www.gitignore.io/?templates=clion
370 |
371 | ### CLion ###
372 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
373 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
374 |
375 | # User-specific stuff
376 | .idea/**/workspace.xml
377 | .idea/**/tasks.xml
378 | .idea/**/usage.statistics.xml
379 | .idea/**/dictionaries
380 | .idea/**/shelf
381 |
382 | # Generated files
383 | .idea/**/contentModel.xml
384 |
385 | # Sensitive or high-churn files
386 | .idea/**/dataSources/
387 | .idea/**/dataSources.ids
388 | .idea/**/dataSources.local.xml
389 | .idea/**/sqlDataSources.xml
390 | .idea/**/dynamic.xml
391 | .idea/**/uiDesigner.xml
392 | .idea/**/dbnavigator.xml
393 |
394 | # Gradle
395 | .idea/**/gradle.xml
396 | .idea/**/libraries
397 |
398 | # Gradle and Maven with auto-import
399 | # When using Gradle or Maven with auto-import, you should exclude module files,
400 | # since they will be recreated, and may cause churn. Uncomment if using
401 | # auto-import.
402 | # .idea/modules.xml
403 | # .idea/*.iml
404 | # .idea/modules
405 |
406 | # CMake
407 | cmake-build-*/
408 |
409 | # Mongo Explorer plugin
410 | .idea/**/mongoSettings.xml
411 |
412 | # File-based project format
413 | *.iws
414 |
415 | # IntelliJ
416 | out/
417 |
418 | # mpeltonen/sbt-idea plugin
419 | .idea_modules/
420 |
421 | # JIRA plugin
422 | atlassian-ide-plugin.xml
423 |
424 | # Cursive Clojure plugin
425 | .idea/replstate.xml
426 |
427 | # Crashlytics plugin (for Android Studio and IntelliJ)
428 | com_crashlytics_export_strings.xml
429 | crashlytics.properties
430 | crashlytics-build.properties
431 | fabric.properties
432 |
433 | # Editor-based Rest Client
434 | .idea/httpRequests
435 |
436 | # Android studio 3.1+ serialized cache file
437 | .idea/caches/build_file_checksums.ser
438 |
439 | # JetBrains templates
440 | **___jb_tmp___
441 |
442 | ### CLion Patch ###
443 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
444 |
445 | # *.iml
446 | # modules.xml
447 | # .idea/misc.xml
448 | # *.ipr
449 |
450 | # Sonarlint plugin
451 | .idea/sonarlint
452 |
453 | # End of https://www.gitignore.io/api/clion
454 |
455 | # vscode
456 | .vscode/
457 |
458 | # References of Paper Summary
459 | The_Single_Server_Queue/
460 | vldb_toain.pdf
461 | ROAD_KNN_VLDB_TECH_V3.pdf
--------------------------------------------------------------------------------
/lab_1/report/doc.tex:
--------------------------------------------------------------------------------
1 | \documentclass{ML}
2 | \usepackage{float}
3 | % 姓名,学号
4 | \infoauthor{朱明彦}{1160300314}
5 |
6 | % 课程类型,实验名称
7 | \infoexp{课程类型}{实验一}
8 |
9 | \infoschool{计算机学院}{高宏}
10 |
11 | \begin{document}
12 | \maketitle
13 |
14 | \tableofcontents
15 | \newpage
16 |
17 | \begin{center}
18 | \textbf{\zihao{3} 实验一 MySQL关系数据库管理系统及SQL语言的使用}
19 | \end{center}
20 |
21 | \section{实验目的}
22 | 掌握 MySQL 关系数据库管理系统的基本命令,并熟练使用 SQL 语言管理
23 | MySQL 数据库。掌握 SQL 语言的使用方法,学会使用 SQL 语言进行关系数据
24 | 库查询,特别是聚集查询、连接查询和嵌套查询。
25 | \section{实验环境}
26 | \begin{itemize}
27 | \item Ubuntu 16.04.5
28 | \item MySQL Ver 14.14 Distrib 5.7.25
29 | \end{itemize}
30 | \section{实验过程及结果}
31 | % 对报告中第 3 部分的实验结果进行截图,作为评分标准。对于 3.2,使用
32 | % MYSQL 基本命令可以查看创建的关系数据库的每个模式(参看第 4 部分 MYSQL
33 | % 手册,做作业之前先练习第 4 部分有助于熟悉 MYSQL 命令),对结果进行截图。
34 | % 对于 3.3,使用 select *语句分别显示每张表中被添加的数据,对结果进行截图。
35 | % 对于 3.1,在你完成 3.2 和 3.3 之后,把输入的 9 条 sql 语句和相应的查询结果截
36 | % 图显示,所以你设计的数据库必须包括 3.1 需要的各种数据。
37 | \subsection{实验任务}
38 | \begin{enumerate}
39 | \item 参加了项目名为"SQL Project"的员工的名字;
40 | \begin{minted}{SQL}
41 | SELECT ENAME
42 | FROM EMPLOYEE, WORKS_ON, PROJECT
43 | WHERE EMPLOYEE.ESSN = WORKS_ON.ESSN AND WORKS_ON.PNO = PROJECT.PNO
44 | AND PROJECT.PNAME = "SQL Project";
45 | \end{minted}
46 | SQL查询结果如图\ref{fig:1}
47 | \begin{figure}[htb]
48 | \centering
49 | \includegraphics[scale=0.4, bb=0 0 148 495]{media/3.1.1.eps}
50 | \caption{}\label{fig:1}
51 | \end{figure}
52 | \item 在"Research Department"工作且工资低于3000元的员工名字和地址;
53 | \begin{minted}{SQL}
54 | SELECT ENAME, ADDRESS
55 | FROM EMPLOYEE, DEPARTMENT
56 | WHERE EMPLOYEE.DNO = DEPARTMENT.DNO
57 | AND DEPARTMENT.DNAME = "Research Department"
58 | AND SALARY < 3000;
59 | \end{minted}
60 | SQL查询结果如图\ref{fig:2}
61 | \begin{figure}[htb]
62 | \centering
63 | \includegraphics[scale=0.5, bb=0 0 815 146]{media/3.1.2.eps}
64 | \caption{}\label{fig:2}
65 | \end{figure}
66 | \item 没有参加项目编号为P1的项目的员工名字;
67 | \begin{minted}{SQL}
68 | SELECT DISTINCT ENAME
69 | FROM EMPLOYEE
70 | WHERE ENAME NOT IN(
71 | SELECT DISTINCT ENAME
72 | FROM EMPLOYEE, WORKS_ON
73 | WHERE WORKS_ON.ESSN = EMPLOYEE.ESSN AND WORKS_ON.PNO = "P1"
74 | );
75 | \end{minted}
76 |
77 | SQL查询结果如图\ref{fig:3},但由于总的查询结果有70条,故此处仅列出部分查询结果。
78 | \begin{figure}[htb]
79 | \centering
80 | \includegraphics[scale=0.4, bb=0 0 147 726]{media/3.1.3.eps}
81 | \caption{}\label{fig:3}
82 | \end{figure}
83 | \item 由张红领导的工作人员的姓名和所在部门;
84 | \begin{minted}{SQL}
85 | SELECT ENAME, DNAME
86 | FROM DEPARTMENT, EMPLOYEE
87 | WHERE EMPLOYEE.DNO = DEPARTMENT.DNO
88 | AND EMPLOYEE.SUPERSSN IN(
89 | SELECT ESSN
90 | FROM EMPLOYEE
91 | WHERE ENAME = "张红"
92 | );
93 | \end{minted}
94 | SQL查询结果如图\ref{fig:4}
95 | \begin{figure}[htb]
96 | \centering
97 | \includegraphics[scale=0.4, bb=0 0 383 124]{media/3.1.4.eps}
98 | \caption{}\label{fig:4}
99 | \end{figure}
100 | \item 至少参加了项目编号为P1和P2的项目的员工号;
101 | \begin{minted}{SQL}
102 | SELECT DISTINCT ESSN
103 | FROM WORKS_ON
104 | WHERE PNO = "P1"
105 | AND ESSN IN(
106 | SELECT DISTINCT ESSN
107 | FROM WORKS_ON
108 | WHERE PNO = "P2"
109 | );
110 | \end{minted}
111 | SQL查询结果如图\ref{fig:5}
112 | \begin{figure}[htb]
113 | \centering
114 | \includegraphics[scale=0.4, bb=0 0 245 142]{media/3.1.5.eps}
115 | \caption{}\label{fig:5}
116 | \end{figure}
117 | \item 参加了全部项目的员工号码和姓名;
118 | \begin{minted}{SQL}
119 | SELECT DISTINCT R1.ESSN, ENAME
120 | FROM WORKS_ON R1, EMPLOYEE
121 | WHERE NOT EXISTS(
122 | SELECT PROJECT.PNO FROM PROJECT
123 | WHERE NOT EXISTS(
124 | SELECT * FROM WORKS_ON R2
125 | WHERE R2.ESSN = R1.ESSN AND R2.PNO = PROJECT.PNO
126 | )
127 | ) AND R1.ESSN = EMPLOYEE.ESSN;
128 | \end{minted}
129 | SQL查询结果如图\ref{fig:6}
130 | \begin{figure}[htb]
131 | \centering
132 | \includegraphics[scale=0.4, bb=0 0 383 103]{media/3.1.6.eps}
133 | \caption{}\label{fig:6}
134 | \end{figure}
135 | \item 员工平均工资低于3000元的部门名称;
136 | \begin{minted}{SQL}
137 | SELECT DNAME
138 | FROM DEPARTMENT, EMPLOYEE
139 | WHERE DEPARTMENT.DNO = EMPLOYEE.DNO
140 | GROUP BY DEPARTMENT.DNO
141 | HAVING AVG(SALARY) < 3000;
142 | \end{minted}
143 | SQL查询结果如图\ref{fig:7}
144 | \begin{figure}[htb]
145 | \centering
146 | \includegraphics[scale=0.4, bb=0 0 311 210]{media/3.1.7.eps}
147 | \caption{}\label{fig:7}
148 | \end{figure}
149 | \item 至少参与了3个项目且工作总时间不超过8小时的员工名字;
150 | \begin{minted}{SQL}
151 | SELECT ENAME FROM EMPLOYEE
152 | WHERE ESSN IN(
153 | SELECT ESSN
154 | FROM WORKS_ON
155 | GROUP BY ESSN HAVING COUNT(PNO) >= 3 AND SUM(HOURS) <= 8
156 | );
157 | \end{minted}
158 | SQL查询结果如图\ref{fig:8}
159 | \begin{figure}[htb]
160 | \centering
161 | \includegraphics[scale=0.4, bb=0 0 148 100]{media/3.1.8.eps}
162 | \caption{}\label{fig:8}
163 | \end{figure}
164 | \item 每个部门员工小时平均工资;
165 | \begin{minted}{SQL}
166 | SELECT DNAME, AVG(SALARY / R.sum) HOURS_SALARY
167 | FROM EMPLOYEE, (
168 | SELECT ESSN, SUM(HOURS) sum
169 | FROM WORKS_ON
170 | GROUP BY WORKS_ON.ESSN) AS R, DEPARTMENT
171 | WHERE R.ESSN = EMPLOYEE.ESSN AND EMPLOYEE.DNO = DEPARTMENT.DNO
172 | GROUP BY DEPARTMENT.DNO;
173 | \end{minted}
174 | SQL查询结果如图\ref{fig:9}
175 | \begin{figure}[htb]
176 | \centering
177 | \includegraphics[scale=0.4, bb=0 0 474 274]{media/3.1.9.eps}
178 | \caption{}\label{fig:9}
179 | \end{figure}
180 | \end{enumerate}
181 | \subsection{关系数据库COMPANY介绍}
182 | \paragraph{表EMPLOYEE} 其模式如图\ref{fig:emp_pattern}所示,其中\texttt{ESSN}即雇员的身份证号为主键,\texttt{SUPERSSN}即雇员直接上司的身份证号为相对其自身的外键;
183 | 对于\texttt{DNO}即雇员所属的部门编号为相对于\texttt{DEPARTMENT}中\texttt{DNO}的外键。
184 | \begin{figure}[htb]
185 | \centering
186 | \includegraphics[scale = 0.5, bb=0 0 639 242]{media/employee_pattern.eps}
187 | \caption{TABLE EMPLOYEE PATTERN}\label{fig:emp_pattern}
188 | \end{figure}
189 | \paragraph{表DEPARTMENT} 其模式如图\ref{fig:dep_pattern}所示,其中\texttt{DNO}即部门编号为主键,\texttt{MGRSSN}即部门领导的身份证号为相对于\texttt{EMPLOYEE}的\texttt{ESSN}的外键。
190 | \begin{figure}[htb]
191 | \centering
192 | \includegraphics[scale = 0.5, bb=0 0 682 196]{media/department_pattern.eps}
193 | \caption{TABLE DEPARTMENT PATTERN}\label{fig:dep_pattern}
194 | \end{figure}
195 | \paragraph{表PROJECT} 其模式如图\ref{fig:pro_pattern}所示,其中\texttt{PRO}即工程编号为主键,\texttt{DNO}即所属部门的编号为相对于\texttt{DEPARTMENT}的\texttt{DNO}的外键。
196 | \begin{figure}[htb]
197 | \centering
198 | \includegraphics[scale = 0.5, bb=0 0 645 236]{media/project_pattern.eps}
199 | \caption{TABLE PROJECT PATTERN}\label{fig:pro_pattern}
200 | \end{figure}
201 | \paragraph{表WORKS\_ON} 其模式如图\ref{fig:works_pattern}所示,其中\texttt{ESSN, PNO}为主键。
202 | \begin{figure}[htb]
203 | \centering
204 | \includegraphics[scale = 0.5, bb=0 0 566 181]{media/works_on_pattern.eps}
205 | \caption{TABLE WORKS\_ON PATTERN}\label{fig:works_pattern}
206 | \end{figure}
207 | \subsection{数据准备}
208 | \paragraph{表EMPLOYEE} 其共包含89条不同的员工信息,此处仅仅截取了部分信息,如图\ref{fig:employee}所示
209 | \begin{figure}[htb]
210 | \centering
211 | \includegraphics[scale = 0.3, bb = 0 0 1487 836]{media/employee.eps}
212 | \caption{TABLE EMPLOYEE}\label{fig:employee}
213 | \end{figure}
214 | \paragraph{表DEPARTMENT} 其共包含9条不同的部门信息,如图\ref{fig:department}所示。
215 | \begin{figure}[htb]
216 | \centering
217 | \includegraphics[scale = 0.5, bb = 0 0 789 307]{media/department.eps}
218 | \caption{TABLE DEPARTMENT}\label{fig:department}
219 | \end{figure}
220 | \paragraph{表PROJECT} 其共包含11条不同的工程信息,如图\ref{fig:project}所示。
221 | \begin{figure}[htb]
222 | \centering
223 | \includegraphics[scale = 0.25, bb = 0 0 1698 356]{media/project.eps}
224 | \caption{TABLE PROJECT}\label{fig:project}
225 | \end{figure}
226 | \paragraph{表WORKS\_ON} 其共包含了204条不同的工作信息,此处仅仅截取了部分信息,如图\ref{fig:works_on}所示。
227 |
228 | \begin{figure}[H]
229 | \centering
230 | \includegraphics[scale = 0.5, bb = 0 0 419 375]{media/works_ON.eps}
231 | \caption{TABLE WORKS\_ON}\label{fig:works_on}
232 | \end{figure}
233 |
234 |
235 | \section{实验心得}
236 |
237 | 对于本次实验,准备实验中所需的数据花费了比较多的时间,另外对于如何具体使用MySQL有了比较新的认识,但总体来说实验难度不大。
238 |
239 | % \appendix
240 |
241 | % \section{源代码}
242 |
243 |
244 | \end{document}
245 |
--------------------------------------------------------------------------------
/lab_2/lab_2/src/Main.java:
--------------------------------------------------------------------------------
1 | import java.sql.*;
2 | import java.util.Scanner;
3 |
4 | public class Main {
5 | private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
6 | private static final String DB_URL = "jdbc:mysql://localhost:3306/COMPANY";
7 | private static final String USER = "root";
8 | private static final String PASSWORD = "mysql";
9 |
10 | private static final String PARA_PNO = "%PNO%";
11 | private static final String PARA_SALARY = "%SALARY%";
12 | private static final String PARA_PNAME = "%PNAME%";
13 | private static final String PARA_DNAME = "%DNAME%";
14 | private static final String PARA_ENAME = "%ENAME%";
15 | private static final String PARA_N = "%N%";
16 | private static final String PARA_HOURS = "%HOURS%";
17 |
18 | private static final String[] queries = {"SELECT ESSN FROM WORKS_ON WHERE PNO = \"" + PARA_PNO + "\"",
19 | "SELECT ENAME FROM EMPLOYEE, WORKS_ON, PROJECT WHERE EMPLOYEE.ESSN = WORKS_ON.ESSN AND PROJECT.PNO = WORKS_ON.PNO AND PROJECT.PNAME = \"" + PARA_PNAME + "\"",
20 | "SELECT ENAME, ADDRESS FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO AND DEPARTMENT.DNAME = \"" + PARA_DNAME + "\"",
21 | "SELECT ENAME, ADDRESS FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO AND DEPARTMENT.DNAME = \"" + PARA_DNAME + "\" AND SALARY < " + PARA_SALARY,
22 | "SELECT ENAME FROM EMPLOYEE WHERE ESSN NOT IN (SELECT DISTINCT ESSN FROM WORKS_ON WHERE WORKS_ON.PNO =\"" + PARA_PNO + "\")",
23 | "SELECT ENAME, DNAME FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO AND EMPLOYEE.SUPERSSN IN (SELECT ESSN FROM EMPLOYEE WHERE ENAME = \"" + PARA_ENAME + "\")",
24 | "SELECT ESSN FROM WORKS_ON WHERE PNO = \"" + PARA_PNO + "1\" AND ESSN IN (SELECT ESSN FROM WORKS_ON WHERE PNO = \"" + PARA_PNO + "2\")",
25 | "SELECT DNAME FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO GROUP BY DEPARTMENT.DNO HAVING AVG(SALARY) < " + PARA_SALARY,
26 | "SELECT ENAME FROM EMPLOYEE, WORKS_ON WHERE EMPLOYEE.ESSN = WORKS_ON.ESSN GROUP BY EMPLOYEE.ESSN HAVING COUNT(PNO) >= " + PARA_N + " AND SUM(HOURS) <= " + PARA_HOURS};
27 |
28 | public static void main(String[] args) {
29 | Connection connection = null;
30 | Statement statement = null;
31 | Scanner cin = new Scanner(System.in);
32 | try {
33 | // 注册JDBC驱动
34 | Class.forName(JDBC_DRIVER);
35 |
36 | // 打开连接
37 | System.out.println("Connecting to MySql Server...");
38 | connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);
39 |
40 | if (!connection.isClosed()) {
41 | System.out.println("Connection Successful!");
42 | // 执行查询
43 | System.out.println("Instances Statement Object..."); // 实例化Statement对象
44 | statement = connection.createStatement();
45 | ResultSet resultSet = null;
46 | int count = 0;
47 | // Query 1
48 | String query = queries[count++];
49 | System.out.println("Query " + count);
50 | System.out.println("Please input pno:");
51 | String pno = cin.nextLine();
52 | query = query.replace(PARA_PNO, pno);
53 | resultSet = statement.executeQuery(query);
54 | while (resultSet.next())
55 | System.out.println(resultSet.getNString("ESSN"));
56 |
57 | // Query 2
58 | query = queries[count++];
59 | System.out.println("Query " + count);
60 | System.out.println("Please input pname:");
61 | String pname = cin.nextLine();
62 | query = query.replace(PARA_PNAME, pname);
63 | resultSet = statement.executeQuery(query);
64 | while (resultSet.next())
65 | System.out.println(resultSet.getNString("ENAME"));
66 |
67 | // Query 3
68 | query = queries[count++];
69 | System.out.println("Query " + count);
70 | System.out.println("Please input dname:");
71 | String dname = cin.nextLine();
72 | query = query.replace(PARA_DNAME, dname);
73 | resultSet = statement.executeQuery(query);
74 | while (resultSet.next())
75 | System.out.println(resultSet.getNString("ENAME") + "\t" + resultSet.getNString("ADDRESS"));
76 |
77 | // Query 4
78 | query = queries[count++];
79 | System.out.println("Query " + count);
80 | System.out.println("Please input dname:");
81 | dname = cin.nextLine();
82 | System.out.println("Please input salary:");
83 | int salary = Integer.parseInt(cin.nextLine());
84 | query = query.replace(PARA_DNAME, dname).replace(PARA_SALARY, String.valueOf(salary));
85 | resultSet = statement.executeQuery(query);
86 | while (resultSet.next())
87 | System.out.println(resultSet.getNString("ENAME") + "\t" + resultSet.getNString("ADDRESS"));
88 |
89 | // Query 5
90 | query = queries[count++];
91 | System.out.println("Query " + count);
92 | System.out.println("Please input pno");
93 | pno = cin.nextLine();
94 | query = query.replace(PARA_PNO, pno);
95 | resultSet = statement.executeQuery(query);
96 | while (resultSet.next())
97 | System.out.println(resultSet.getNString("ENAME"));
98 |
99 | // Query 6
100 | query = queries[count++];
101 | System.out.println("Query " + count);
102 | System.out.println("Please input ename");
103 | String ename = cin.nextLine();
104 | query = query.replace(PARA_ENAME, ename);
105 | resultSet = statement.executeQuery(query);
106 | while (resultSet.next())
107 | System.out.println(resultSet.getNString("ENAME") + "\t" + resultSet.getNString("DNAME"));
108 |
109 | // Query 7
110 | query = queries[count++];
111 | System.out.println("Query " + count);
112 | System.out.println("Please input pno1");
113 | pno = cin.nextLine();
114 | query = query.replace(PARA_PNO+1, pno);
115 | System.out.println("Please input pno2");
116 | pno = cin.nextLine();
117 | query = query.replace(PARA_PNO+2, pno);
118 | resultSet = statement.executeQuery(query);
119 | while (resultSet.next())
120 | System.out.println(resultSet.getNString("ESSN"));
121 |
122 | // Query 8
123 | query = queries[count++];
124 | System.out.println("Query " + count);
125 | System.out.println("Please input salary:");
126 | salary = Integer.parseInt(cin.nextLine());
127 | query = query.replace(PARA_SALARY, String.valueOf(salary));
128 | resultSet = statement.executeQuery(query);
129 | while (resultSet.next())
130 | System.out.println(resultSet.getNString("DNAME"));
131 |
132 | // Query 9
133 | query = queries[count++];
134 | System.out.println("Query " + count);
135 | System.out.println("Please input n:");
136 | int n = Integer.parseInt(cin.nextLine());
137 | query = query.replace(PARA_N, String.valueOf(n));
138 | System.out.println("Please input hours:");
139 | int hours = Integer.parseInt(cin.nextLine());
140 | query = query.replace(PARA_HOURS, String.valueOf(hours));
141 | resultSet = statement.executeQuery(query);
142 | while (resultSet.next())
143 | System.out.println(resultSet.getNString("ENAME"));
144 |
145 |
146 | resultSet.close();
147 |
148 | } else {
149 | System.out.println("Connection Failed, maybe mysql is close.");
150 | System.out.println("GoodBye~");
151 | }
152 | } catch (ClassNotFoundException | SQLException e) {
153 | // 处理JDBC错误 处理Class.forName错误
154 | e.printStackTrace();
155 | } finally {
156 | try {
157 | if (statement != null)
158 | statement.close();
159 | } catch (SQLException e) {
160 | e.printStackTrace();
161 | }
162 |
163 | try {
164 | if (connection != null)
165 | connection.close();
166 | } catch (SQLException e) {
167 | e.printStackTrace();
168 | }
169 | }
170 | }
171 | }
172 | //
173 | //P1
174 | //SQL Project
175 | //International Department
176 | //International Department
177 | //4000
178 | //P2
179 | //张红
180 | //P1
181 | //P2
182 | //3000
183 | //3
184 | //8
185 |
186 |
187 |
--------------------------------------------------------------------------------
/homework_3/homework_3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,a4paper]{article}
2 | % 使用12pt(对应于中文的小四号字)
3 | % \usepackage{xeCJK}
4 | % \setmainfont{Times New Roman}
5 | % \setCJKmainfont[BoldFont=Hei]{Hei}
6 | \usepackage{array,ragged2e,pst-node,pst-dbicons}
7 | \usepackage{ctex}
8 | \usepackage{geometry} %设置页边距的宏包
9 | \usepackage{titlesec} %设置页眉页脚的宏包
10 | \usepackage{amssymb}
11 | \usepackage{amsmath}
12 | \usepackage{tikz-er2}
13 | \usepackage{graphviz}
14 | \geometry{left=3.17cm,right=3.17cm,top=2.54cm,bottom=2.54cm} %设置 上、左、下、右 页边距
15 | \begin{document}
16 | \newpagestyle{main}{
17 | \sethead{哈尔滨工业大学}{数据库系统\_第三次作业}{1160300314 朱明彦} %设置页眉
18 | % \setfoot{左页脚}{中页脚}{右页脚} %设置页脚,可以在页脚添加 \thepage 显示页数
19 | \setfoot{}{}{\thepage}
20 | \headrule % 添加页眉的下划线
21 | % \footrule %添加页脚的下划线
22 | }
23 | \pagestyle{main} %使用该style
24 | \usetikzlibrary{positioning}
25 | \usetikzlibrary{shadows}
26 | \usetikzlibrary{arrows}
27 | \tikzstyle{every entity} = [top color=white, bottom color=blue!30,
28 | draw=blue!50!black!100, drop shadow]
29 | \tikzstyle{every weak entity} = [drop shadow={shadow xshift=.7ex,
30 | shadow yshift=-.7ex}]
31 | \tikzstyle{every attribute} = [top color=white, bottom color=yellow!20,
32 | draw=yellow, node distance=1cm, drop shadow]
33 | \tikzstyle{every relationship} = [top color=white, bottom color=red!20,
34 | draw=red!50!black!100, drop shadow]
35 | \tikzstyle{every isa} = [top color=white, bottom color=green!20,
36 | draw=green!50!black!100, drop shadow]
37 |
38 | % \setlength{\baselineskip}{15.6pt}
39 | \setlength{\parskip}{0pt}
40 | \renewcommand{\baselinestretch}{1.5}
41 |
42 | \paragraph{一、}
43 | \begin{enumerate}
44 | \item \textbf{实体}是ER模型中的基本对象,是现实世界中各种失误的抽象。
45 | \item \textbf{属性}是每个实体所拥有的一组特征或性质,实体的属性值是数据库中存储的主要数据。
46 | \item \textbf{联系}是不同实体集之间的某种关联,可以使用联系集定义也可以通过实体的属性定义。
47 | \end{enumerate}
48 | \paragraph{二、}
49 | \begin{center}
50 | \scalebox{0.75}{
51 | \begin{tikzpicture}[node distance=1.5cm, every edge/.style={link}]
52 |
53 | \node[entity] (customer) {顾客};
54 | \node[attribute] (cname) [above=of customer] {姓名} edge (customer);
55 | \node[attribute] (cid) [above left=of customer] {\key{社会安全号码}} edge (customer);
56 | \node[attribute] (c_tel) [above right=of customer] {电话} edge (customer);
57 |
58 | \node[relationship] (have) [below=of customer] {拥有} edge node[auto] {1} (customer);
59 | \node[entity] (address) [below=of have] {地址} edge node[auto] {m} (have);
60 | \node[attribute] (state) [left=of address] {\key{州名}} edge (address);
61 | \node[attribute] (city) [above left=of address] {\key{城市}} edge (address);
62 | \node[attribute] (street) [below left=of address] {\key{街道}} edge (address);
63 | \node[multi attribute] (telephone) [below=of address] {电话} edge (address);
64 |
65 | % \node[entity] (telephone) [below=of have] {电话} edge node[auto] {n} (have);
66 | % \node[attribute] (telephone_number) [below=of telephone] {\key{电话号码}} edge (telephone);
67 |
68 | \node[relationship] (own) [right=of have] {持有} edge node[auto] {1} (customer);
69 | \node[entity] (account) [below=of own] {账户} edge node[auto] {n} (own);
70 |
71 | \node[attribute] (acc_id) [above right=of account] {\key{号码}} edge (account);
72 | \node[attribute] (type) [right=of account] {类型} edge (account);
73 | \node[attribute] (incomde) [below right=of account] {收支情况} edge (account);
74 | % \node[isa] (isa) [below=1cm of emp] {ISA} edge (emp);
75 |
76 | % \node[entity] (mec) [below left=1cm of isa] {Mechanic} edge (isa);
77 | % \node[entity] (sal) [below right=1cm of isa] {Salesman} edge (isa);
78 |
79 | % \node[relationship] (does) [left=of mec] {Does} edge (mec);
80 |
81 | % \node[weak entity] (rep) [below=of does] {RepairJob} edge (does);
82 | % \node[attribute] (rnum) [left=of rep] {\discriminator{Number}} edge (rep);
83 | % \node[attribute] (desc) [above left=of rep] {Description} edge (rep);
84 | % \node[attribute] (cost) [below left=of rep] {Cost} edge (rep);
85 | % \node[attribute] (mat) [left=0.5cm of cost] {Parts} edge (cost);
86 | % \node[attribute] (work) [below left=0.5cm of cost] {Work} edge (cost);
87 |
88 | % \node[ident relationship] (reps) [below=of rep] {Repairs} edge [total] (rep);
89 |
90 | % \node[entity] (car) [right=of reps] {Car} edge [<-] (reps);
91 | % \node[attribute] (lic) [above=of car] {\key{License}} edge (car);
92 | % \node[attribute] (mod) [below=of car] {Model} edge (car);
93 | % \node[attribute] (year) [below right=of car] {Year} edge (car);
94 | % \node[attribute] (manu) [below left=1.5cm of car] {Manufacturer} edge (car);
95 |
96 | % \node[relationship] (buy) [below=of sal] {Buys};
97 | % \node[attribute] (pri) [above left=of buy] {Price} edge (buy);
98 | % \node[attribute] (sdate) [left=of buy] {Date} edge (buy);
99 | % \node[attribute] (bval) [below left=of buy] {Value} edge (buy);
100 |
101 | % \node[relationship] (sel) [right=of buy] {Sells};
102 | % \node[attribute] (sdate) [above right=of sel] {Date} edge (sel);
103 | % \node[derived attribute] (sval) [right=of sel] {Value} edge (sel);
104 | % \node[attribute] (com) [below right=of sel] {Comission} edge (sel);
105 |
106 | % \draw[link] (car.10) -| (buy) (buy) edge (sal);
107 | % \draw[link] (car.-10) -| (sel) (sel) |- (sal);
108 |
109 | % \node[entity] (cli) [below right=0.5cm and 3.7cm of car] {Client};
110 | % \node[attribute] (cid) [right=of cli] {\key{ID}} edge (cli);
111 | % \node[attribute] (cname) [below left=of cli] {Name} edge (cli);
112 | % \node[multi attribute] (cphone) [below right=of cli] {Phone} edge (cli);
113 | % \node[attribute] (cadd) [below=of cli] {Address} edge (cli);
114 |
115 | % \draw[link] (cli.70) |- node [pos=0.05, auto, swap] {buyer} (sel);
116 | % \draw[link] (cli.110) |- node [pos=0.05, auto] {seller} (buy);
117 |
118 | \end{tikzpicture}
119 | }
120 |
121 | \end{center}
122 | \begin{enumerate}
123 | \item ER图如上所示。
124 | \item 转化得到的关系模式如下所示:
125 | \begin{itemize}
126 | \item \texttt{顾客(\underline{社会安全号码},姓名,电话)}
127 | \item \texttt{顾客地址(\underline{社会安全号码},城市,州名,街道)}
128 | \item \texttt{地址(\underline{城市},\underline{州名},\underline{街道})}
129 | \item \texttt{地址电话(\underline{城市}, \underline{州名},\underline{街道},电话)}
130 | \item \texttt{账户(\underline{号码},社会安全号码,类型,收支情况)}
131 | \end{itemize}
132 | \item \begin{enumerate}
133 | \item 对于顾客表,其主键为社会安全号码,不能为空且可以唯一标示一个顾客实体。
134 | \item 对于顾客地址表,其主键为社会安全号码,城市、州名和街道是相对于表地址电话的外键,其在地址电话表中必须存在。
135 | \item 对于地址表,其主键为城市、州名和街道,不为空且可以唯一标示一个地址实体。
136 | \item 对于地址电话表,其主键城市、州名和街道,不能为空且可以唯一标示一个地址实体,外键为城市、州名和街道相对于地址表,其在地址表中必须存在。
137 | \item 对于账户表,其主键为号码不能为空,且可以唯一标示一个账户实体,社会安全号码为相对于顾客表的外键,其在顾客表中必须存在。
138 | \end{enumerate}
139 | \end{enumerate}
140 | \newpage
141 | \paragraph{三、}
142 | \begin{center}
143 | \scalebox{0.75}{
144 | \begin{tikzpicture}[node distance=1.5cm, every edge/.style={link}]
145 |
146 | \node[relationship] (sale) {销售};
147 | \node[attribute] (month_sales) [above=of sale] {月销售量} edge (sale);
148 | \node[entity] (shop) [left=of sale]{商店} edge node[above] {m} (sale);
149 | \node[entity] (goods) [right=of sale] {商品} edge node[above] {n} (sale);
150 |
151 | \node[attribute] (s_id) [above left=of shop] {\key{商店编号}} edge (shop);
152 | \node[attribute] (s_name) [left=of shop] {商店名} edge (shop);
153 | \node[attribute] (s_add) [below left=of shop] {地址} edge (shop);
154 | \node[attribute] (g_id) [above right=of goods] {\key{商品号}} edge (goods);
155 | \node[attribute] (g_name) [right=of goods] {商品名} edge (goods);
156 | \node[attribute] (g_size) [below right=of goods] {规格} edge (goods);
157 | \node[attribute] (g_prize) [below=of g_size] {单价} edge (goods);
158 |
159 | \node[relationship] (work) [below=of sale] {聘用} edge node[auto] {1} (shop);
160 | \node[attribute] (work_longth) [left=of work] {聘期} edge (work);
161 | \node[attribute] (salary) [right=of work] {月薪} edge (work);
162 | \node[entity] (worker) [below=of work] {职工} edge node[auto] {n} (work);
163 |
164 | \node[attribute] (w_id) [left=of worker] {\key{职工编号}} edge (worker);
165 | \node[attribute] (w_name) [below left=of worker] {姓名} edge (worker);
166 | \node[attribute] (w_sex) [below right=of worker] {性别} edge (worker);
167 | \node[attribute] (w_sale) [right=of worker] {业绩} edge (worker);
168 | \end{tikzpicture}
169 | }
170 | \end{center}
171 | \begin{enumerate}
172 | \item ER图如上所示。
173 | \item 将ER图转换为关系模式,如下所示
174 | \begin{enumerate}
175 | \item \texttt{商店(\underline{商店编号}, 商店名, 地址)}
176 | \item \texttt{商品(\underline{商品号}, 商品名, 规格, 单价)}
177 | \item \texttt{职工(\underline{职工编号}, \underline{商店编号}, 姓名, 性别, 业绩, 月薪, 聘期)}
178 | \item \texttt{销售量(\underline{商店编号}, \underline{商品号}, 月销售量)}
179 | \end{enumerate}
180 | \item \begin{enumerate}
181 | \item 对于商店表,主键为商店编号。
182 | \item 对于商品表,主键为商品号。
183 | \item 对于职工表,主键为商店编号和职工编号, 其外键为商店编号相对于商店表。
184 | \item 对于销售量, 主键为商店编号和商品号。
185 | \end{enumerate}
186 | \end{enumerate}
187 |
188 | \end{document}
--------------------------------------------------------------------------------
/homework_4/homework_4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt, a4paper]{article}
2 | % 使用12pt(对应于中文的小四号字)
3 | % \usepackage{xeCJK}
4 | % \setmainfont{Times New Roman}
5 | % \setCJKmainfont[BoldFont=Hei]{Hei}
6 | \usepackage{array, ragged2e, pst-node, pst-dbicons}
7 | \usepackage{ctex}
8 | \usepackage{geometry} %设置页边距的宏包
9 | \usepackage{titlesec} %设置页眉页脚的宏包
10 | \usepackage{amssymb}
11 | \usepackage{amsmath}
12 | \usepackage{tikz-er2}
13 | \usepackage{graphviz}
14 | \usepackage{minted}
15 | \newminted{text}{frame=lines, framesep=2mm}
16 | \newminted{python}{frame=lines, framesep=2mm, linenos}
17 | \geometry{left=3.17cm, right=3.17cm, top=2.54cm, bottom=2.54cm} %设置 上、左、下、右 页边距
18 | \begin{document}
19 | \newpagestyle{main}{
20 | \sethead{哈尔滨工业大学}{数据库系统\_第四次作业}{1160300314 朱明彦} %设置页眉
21 | % \setfoot{左页脚}{中页脚}{右页脚} %设置页脚, 可以在页脚添加 \thepage 显示页数
22 | \setfoot{}{}{\thepage}
23 | \headrule % 添加页眉的下划线
24 | % \footrule %添加页脚的下划线
25 | }
26 | \pagestyle{main} %使用该style
27 | \usetikzlibrary{positioning}
28 | \usetikzlibrary{shadows}
29 | \usetikzlibrary{arrows}
30 | \tikzstyle{every entity} = [top color=white, bottom color=blue!30,
31 | draw=blue!50!black!100, drop shadow]
32 | \tikzstyle{every weak entity} = [drop shadow={shadow xshift=.7ex,
33 | shadow yshift=-.7ex}]
34 | \tikzstyle{every attribute} = [top color=white, bottom color=yellow!20,
35 | draw=yellow, node distance=1cm, drop shadow]
36 | \tikzstyle{every relationship} = [top color=white, bottom color=red!20,
37 | draw=red!50!black!100, drop shadow]
38 | \tikzstyle{every isa} = [top color=white, bottom color=green!20,
39 | draw=green!50!black!100, drop shadow]
40 |
41 | % \setlength{\baselineskip}{15.6pt}
42 | % \setlength{\parskip}{0pt}
43 | \renewcommand{\baselinestretch}{1.5}
44 |
45 | \begin{enumerate}
46 | \item
47 | 等价, 理由如下:
48 | \begin{itemize}
49 | \item 首先往证, $F^+ \subseteq G^+$.
50 | \begin{itemize}
51 | \item 由于$A \to CD \in G$, 所以有$A\to C, A\to D$, 进而有$AC \to D$, 从而$G$蕴含$A\to C, AC\to D$;
52 | \item 又由于$E\to AH$, 有$E\to A, E\to H$, 又$A\to D \in G^+$, 从而有$E\to D$, 故$G$蕴含$E\to AD, E\to H$.
53 | \end{itemize}
54 | 综上两点, 有$F^+ \subseteq G^+$.
55 | \item 再证, $G^+ \subseteq F^+$.
56 | \begin{itemize}
57 | \item 由于$A\to C, A\to A$且有$AC\to D$, 从而有$AC\to D$, 进而有$A\to CD$, 即$F$蕴含$A\to CD$.
58 | \item 又由于$E\to AD$, 易有$E\to A$, 又$E\to H$, 从而有$E\to AH$, 即$F$蕴含$E\to AH$.
59 | \end{itemize}
60 | 综上两点, 有$G^+ \subseteq F^+$.
61 | \end{itemize}
62 | 综上所述, 可以有$F^+ = G^+$, 从而$F$和$G$等价.
63 | \item \begin{enumerate}
64 | \item[(1)] \textbf{3NF}.由于候选键是XY和XZ, 从而对于X,Y和Z而言均为键属性, 不存在非键属性对候选键的传递依赖和部分函数依赖, 所以至少为3NF; 又由于键属性Z对候选键XZ存在部分函数依赖, 故其不是BCNF. 所以其为3NF.
65 | \item[(2)] \textbf{BCNF}. R的候选键为X和Y, 根据定义在函数依赖的左部均为候选键, 故其为BCNF.
66 | \item[(3)] \textbf{1NF}. R的候选键为WX, 又由于$X\to Z, WX\to X$, 所以存在$WX\to Z$这个部分函数依赖, 所以其为1NF.
67 | \end{enumerate}
68 | \item \begin{enumerate}
69 | \item[(1)] 首先将函数依赖集$F$转化为对应的函数右部仅有1个属性的形式.\\ 即$F=\{E\to G, G\to E, F\to E, F\to G, H\to E, H\to G, FH\to E\}$.
70 | \item[(2)] 去掉左部冗余的属性, 由于$FH\to E, F\to E$, 从而$FH\to E$冗余\\ 化简后为$F=\{E\to G, G\to E, F\to E, F\to G, H\to E, H\to G\}$.
71 | \item[(3)] 去掉冗余的函数依赖, 由于$F\to E, E\to G$可以得到$F\to G$, 从而后者冗余;同理可以有$H\to G$冗余,\\化简后的结果$F=\{E\to G, G\to E, F\to E, H\to E\}$.
72 | \end{enumerate}
73 | 故最终的结果为$F=\{E\to G, G\to E, F\to E, H\to E\}$.
74 | \item 首先求得$F_m=\{A\to D, E\to D, D\to B, BC\to D, CD\to A\}$, 进而求得保持函数依赖的关系模式分解为$\rho = \{AD, ED, BD, BCD, ACD\}$
75 | \item \begin{enumerate}
76 | \item[(1)] 根据L类的定义, $B, E$是L类属性, 且此处不存在N类属性. 又$X_{BE}^+ = \{ABCDE\}$, 从而$\{BE\}$是唯一候选键.
77 | \item[(2)] 初始化后的结果如表\ref{tab:1}所示, 在依次考察完所有的依赖集之后, 如表\ref{tab:6}所示, 其与初始化后的表\ref{tab:1}有不同且没有任意一行包含所有$a_i$, 故开始第二轮依次考察所有的依赖;
78 | 第二轮考察的最终结果如表\ref{tab:8}所示, 可以看到没有任意一行中包含$a_i$, 其相较与表\ref{tab:7}没发生变化, 故\textbf{此处不是无损连接分解}.
79 | \begin{figure}[H]
80 | \begin{minipage}[b]{0.5\linewidth}
81 | \centering
82 | \begin{tabular}{|l|l|l|l|l|l|}
83 | \hline
84 | & A & B & C & D & E \\ \hline
85 | AD & $a_1$ & $b_{12}$ & $b_{13}$ & $a_4$ & $a_5$ \\ \hline
86 | AB & $a_1$ & $a_2$ & $b_{23}$ & $b_{24}$ & $b_{25}$ \\ \hline
87 | BC & $b_{31}$ & $a_2$ & $a_3$ & $b_{34}$ & $b_{35}$ \\ \hline
88 | CDE & $b_{41}$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
89 | AE & $a_1$ & $b_{52}$ & $b_{53}$ & $b_{54}$ & $a_5$ \\ \hline
90 | \end{tabular}
91 | \caption{初始化}\label{tab:1}
92 | \end{minipage}
93 | \begin{minipage}[b]{0.5\linewidth}
94 | \centering
95 | \begin{tabular}{|l|l|l|l|l|l|}
96 | \hline
97 | & A & B & C & D & E \\ \hline
98 | AD & $a_1$ & $b_{12}$ & $b_{13}$ & $a_4$ & $a_5$ \\ \hline
99 | AB & $a_1$ & $a_2$ & $b_{13}$ & $b_{24}$ & $b_{25}$ \\ \hline
100 | BC & $b_{31}$ & $a_2$ & $a_3$ & $b_{34}$ & $b_{35}$ \\ \hline
101 | CDE & $b_{41}$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
102 | AE & $a_1$ & $b_{52}$ & $b_{13}$ & $b_{54}$ & $a_5$ \\ \hline
103 | \end{tabular}
104 | \caption{$A\to C$}\label{tab:2}
105 | \end{minipage}
106 | \end{figure}
107 | \begin{figure}[H]
108 | \begin{minipage}[b]{0.5\linewidth}
109 | \centering
110 | \begin{tabular}{|l|l|l|l|l|l|}
111 | \hline
112 | & A & B & C & D & E \\ \hline
113 | AD & $a_1$ & $b_{12}$ & $b_{13}$ & $a_4$ & $a_5$ \\ \hline
114 | AB & $a_1$ & $a_2$ & $b_{13}$ & $a_4$ & $b_{25}$ \\ \hline
115 | BC & $b_{31}$ & $a_2$ & $a_3$ & $a_4$ & $b_{35}$ \\ \hline
116 | CDE & $b_{41}$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
117 | AE & $a_1$ & $b_{52}$ & $b_{13}$ & $a_4$ & $a_5$ \\ \hline
118 | \end{tabular}
119 | \caption{$C\to D$}\label{tab:3}
120 | \end{minipage}
121 | \begin{minipage}[b]{0.5\linewidth}
122 | \centering
123 | \begin{tabular}{|l|l|l|l|l|l|}
124 | \hline
125 | & A & B & C & D & E \\ \hline
126 | AD & $a_1$ & $b_{12}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
127 | AB & $a_1$ & $a_2$ & $a_3$ & $a_4$ & $b_{25}$ \\ \hline
128 | BC & $b_{31}$ & $a_2$ & $a_3$ & $a_4$ & $b_{35}$ \\ \hline
129 | CDE & $b_{41}$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
130 | AE & $a_1$ & $b_{52}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
131 | \end{tabular}
132 | \caption{$B\to C$}\label{tab:4}
133 | \end{minipage}
134 | \end{figure}
135 | \begin{figure}[H]
136 | \begin{minipage}[b]{0.5\linewidth}
137 | \centering
138 | \begin{tabular}{|l|l|l|l|l|l|}
139 | \hline
140 | & A & B & C & D & E \\ \hline
141 | AD & $a_1$ & $b_{12}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
142 | AB & $a_1$ & $a_2$ & $a_3$ & $a_4$ & $b_{25}$ \\ \hline
143 | BC & $b_{31}$ & $a_2$ & $a_3$ & $a_4$ & $b_{35}$ \\ \hline
144 | CDE & $b_{41}$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
145 | AE & $a_1$ & $b_{52}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
146 | \end{tabular}
147 | \caption{$DE\to C$}\label{tab:5}
148 | \end{minipage}
149 | \begin{minipage}[b]{0.5\linewidth}
150 | \centering
151 | \begin{tabular}{|l|l|l|l|l|l|}
152 | \hline
153 | & A & B & C & D & E \\ \hline
154 | AD & $a_1$ & $b_{12}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
155 | AB & $a_1$ & $a_2$ & $a_3$ & $a_4$ & $b_{25}$ \\ \hline
156 | BC & $b_{31}$ & $a_2$ & $a_3$ & $a_4$ & $b_{35}$ \\ \hline
157 | CDE & $a_1$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
158 | AE & $a_1$ & $b_{52}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
159 | \end{tabular}
160 | \caption{$CE\to A$}\label{tab:6}
161 | \end{minipage}
162 | \end{figure}
163 | \begin{figure}[H]
164 | \begin{minipage}[b]{0.5\linewidth}
165 | \centering
166 | \begin{tabular}{|l|l|l|l|l|l|}
167 | \hline
168 | & A & B & C & D & E \\ \hline
169 | AD & $a_1$ & $b_{12}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
170 | AB & $a_1$ & $a_2$ & $a_3$ & $a_4$ & $b_{25}$ \\ \hline
171 | BC & $b_{31}$ & $a_2$ & $a_3$ & $a_4$ & $b_{35}$ \\ \hline
172 | CDE & $a_1$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
173 | AE & $a_1$ & $b_{52}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
174 | \end{tabular}
175 | \caption{第2轮考察$A\to C$}\label{tab:7}
176 | \end{minipage}
177 | \begin{minipage}[b]{0.5\linewidth}
178 | \centering
179 | \begin{tabular}{|l|l|l|l|l|l|}
180 | \hline
181 | & A & B & C & D & E \\ \hline
182 | AD & $a_1$ & $b_{12}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
183 | AB & $a_1$ & $a_2$ & $a_3$ & $a_4$ & $b_{25}$ \\ \hline
184 | BC & $b_{31}$ & $a_2$ & $a_3$ & $a_4$ & $b_{35}$ \\ \hline
185 | CDE & $a_1$ & $b_{42}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
186 | AE & $a_1$ & $b_{52}$ & $a_3$ & $a_4$ & $a_5$ \\ \hline
187 | \end{tabular}
188 | \caption{第2轮考察完所有的依赖}\label{tab:8}
189 | \end{minipage}
190 | \end{figure}
191 |
192 | \item[(3)] 由于$BE$是键, 且不存在任意一个依赖的左部是$BE$, 随机选择一个函数依赖即可开始算法.
193 | \begin{enumerate}
194 | \item 对于$A\to C$, A不是候选键, 所以我们可以拆分成两个关系$(AC), (ABDE)$. 则对于$<\{AC\}, \{A\to C\}>$, $A$是主键, 从而$(AC)$是BCNF;又$<\{ABDE\}, \{A\to D, B\to D, DE\to A\}>$, 候选键为$\{BE\}$, 故需要继续拆分$\{ABDE\}$.
195 | \item 对于$A\to D$, A不是候选键, 所以我们可以将$(ABDE)$拆分成两个关系, $(AD), (ABE)$. 则对于$<\{AD\}, \{A\to D\}>$, 候选键为$A$, 其为BCNF; 又对$<\{ABE\}, \emptyset >$, 其所有属性均为键属性, 故其为BCNF, 算法结束.
196 | \end{enumerate}
197 | 最终拆分的结果为$(AC), (AD), (ABE)$.
198 | \end{enumerate}
199 | \item \begin{enumerate}
200 | \item[(1)] 因为\{课程编号,章节编号,学期,年\}$^+ = U$ 且 \{上课时间,教室, 课程编号, 章节编号\}$^+ = U$, 故候选键为\{课程编号,章节编号,学期,年\}和\{上课时间,教室, 课程编号, 章节编号\}, 并\textbf{选择\{上课时间,教室, 课程编号, 章节编号\}为主键}.
201 | \item[(2)] 由于\{课程编号\} $\to$ \{学院, 课时, 等级\}的左部不为候选键, 所以$R$不是BCNF. 因此使用算法将其分解为BCNF.
202 | \begin{enumerate}
203 | \item 对于\{课程编号\} $\to$ \{学院, 课时, 等级\}, 其左部不为候选键, 故将R拆分为2个关系\{课程编号, 章节编号, 教师编号, 学期, 年, 上课时间, 教室, 学生数量\}和\{学院, 课时, 等级\}.
204 | 并且对于两个关系, 其函数依赖的左部均为候选码(第2个关系的函数依赖集为空集), 算法结束.
205 | \end{enumerate}
206 | \textbf{规范化后的结果为\{课程编号, 章节编号, 教师编号, 学期, 年, 上课时间, 教室, 学生数量\}和\{学院, 课时, 等级\}
207 | } \end{enumerate}
208 | \end{enumerate}
209 | \end{document}
210 |
--------------------------------------------------------------------------------
/lab_2/lab_2/src/COMPANY_Query.java:
--------------------------------------------------------------------------------
1 | import org.apache.commons.cli.*;
2 |
3 | import java.sql.*;
4 | import java.util.Objects;
5 |
6 |
7 | public class COMPANY_Query {
8 | private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
9 | private static final String DB_URL = "jdbc:mysql://localhost:3306/COMPANY";
10 | private static final String USER = "root";
11 | private static final String PASSWORD = "mysql";
12 |
13 | private static final String PARA_PNO = "%PNO%";
14 | private static final String PARA_SALARY = "%SALARY%";
15 | private static final String PARA_PNAME = "%PNAME%";
16 | private static final String PARA_DNAME = "%DNAME%";
17 | private static final String PARA_ENAME = "%ENAME%";
18 | private static final String PARA_N = "%N%";
19 | private static final String PARA_HOURS = "%HOURS%";
20 |
21 | private static final String[] queries = {"SELECT ESSN FROM WORKS_ON WHERE PNO = \"" + PARA_PNO + "\"",
22 | "SELECT ENAME FROM EMPLOYEE, WORKS_ON, PROJECT WHERE EMPLOYEE.ESSN = WORKS_ON.ESSN AND PROJECT.PNO = WORKS_ON.PNO AND PROJECT.PNAME = \"" + PARA_PNAME + "\"",
23 | "SELECT ENAME, ADDRESS FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO AND DEPARTMENT.DNAME = \"" + PARA_DNAME + "\"",
24 | "SELECT ENAME, ADDRESS FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO AND DEPARTMENT.DNAME = \"" + PARA_DNAME + "\" AND SALARY < " + PARA_SALARY,
25 | "SELECT ENAME FROM EMPLOYEE WHERE ESSN NOT IN (SELECT DISTINCT ESSN FROM WORKS_ON WHERE WORKS_ON.PNO =\"" + PARA_PNO + "\")",
26 | "SELECT ENAME, DNAME FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO AND EMPLOYEE.SUPERSSN IN (SELECT ESSN FROM EMPLOYEE WHERE ENAME = \"" + PARA_ENAME + "\")",
27 | "SELECT ESSN FROM WORKS_ON WHERE PNO = \"" + PARA_PNO + "1\" AND ESSN IN (SELECT ESSN FROM WORKS_ON WHERE PNO = \"" + PARA_PNO + "2\")",
28 | "SELECT DNAME FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DNO = DEPARTMENT.DNO GROUP BY DEPARTMENT.DNO HAVING AVG(SALARY) < " + PARA_SALARY,
29 | "SELECT ENAME FROM EMPLOYEE, WORKS_ON WHERE EMPLOYEE.ESSN = WORKS_ON.ESSN GROUP BY EMPLOYEE.ESSN HAVING COUNT(PNO) >= " + PARA_N + " AND SUM(HOURS) <= " + PARA_HOURS};
30 |
31 | public static void main(String[] args) {
32 | Options options = new Options();
33 | Option number = new Option("q", "number", true, "Number of paras");
34 | number.setRequired(true);
35 | options.addOption(number);
36 |
37 | Option para = new Option("p", "para", true, "Parameters");
38 | para.setArgs(Option.UNLIMITED_VALUES);
39 | para.setRequired(true);
40 | options.addOption(para);
41 |
42 | CommandLineParser parser = new DefaultParser();
43 | HelpFormatter formatter = new HelpFormatter();
44 | CommandLine cmd;
45 | try {
46 | cmd = parser.parse(options, args);
47 | int num = Integer.parseInt(cmd.getOptionValue("number"));
48 | String[] paras = cmd.getOptionValues("para");
49 |
50 | // System.out.println(num);
51 | // System.out.println(Arrays.toString(paras));
52 |
53 | Connection connection = null;
54 | Statement statement = null;
55 | try {
56 | // 注册JDBC驱动
57 | Class.forName(JDBC_DRIVER);
58 |
59 | // 打开连接
60 | System.out.println("Connecting to MySql Server...");
61 | connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);
62 |
63 | if (!connection.isClosed()) {
64 | System.out.println("Connection Successful!");
65 | // 执行查询
66 | System.out.println("Instances Statement Object..."); // 实例化Statement对象
67 | statement = connection.createStatement();
68 | ResultSet resultSet = null;
69 | String query;
70 | if (num == 1) {
71 | // Query 1
72 | query = queries[num - 1];
73 | assert paras.length == 1;
74 | System.out.println("Query " + num);
75 | query = query.replace(PARA_PNO, paras[0]);
76 | resultSet = statement.executeQuery(query);
77 | System.out.println("ESSN");
78 | while (resultSet.next())
79 | System.out.println(resultSet.getNString("ESSN"));
80 | } else if (num == 2) {
81 | // Query 2
82 | assert paras.length == 1;
83 | query = queries[num - 1];
84 | System.out.println("Query " + num);
85 | query = query.replace(PARA_PNAME, paras[0]);
86 | resultSet = statement.executeQuery(query);
87 | System.out.println("ENAME");
88 | while (resultSet.next())
89 | System.out.println(resultSet.getNString("ENAME"));
90 | } else if (num == 3) {
91 | // Query 3
92 | query = queries[num - 1];
93 | assert paras.length == 1;
94 | System.out.println("Query " + num);
95 | query = query.replace(PARA_DNAME, paras[0]);
96 | resultSet = statement.executeQuery(query);
97 | System.out.println("ENAME");
98 | while (resultSet.next())
99 | System.out.println(resultSet.getNString("ENAME") + "\t" + resultSet.getNString("ADDRESS"));
100 | } else if (num == 4) {
101 | // Query 4
102 | query = queries[num - 1];
103 | assert paras.length == 2;
104 | System.out.println("Query " + num);
105 | query = query.replace(PARA_DNAME, paras[0]).replace(PARA_SALARY, paras[1]);
106 | resultSet = statement.executeQuery(query);
107 | System.out.println("ENAME\tADDRESS");
108 | while (resultSet.next())
109 | System.out.println(resultSet.getNString("ENAME") + "\t" + resultSet.getNString("ADDRESS"));
110 | } else if (num == 5) {
111 | // Query 5
112 | query = queries[num - 1];
113 | assert paras.length == 1;
114 | System.out.println("Query " + num);
115 | query = query.replace(PARA_PNO, paras[0]);
116 | resultSet = statement.executeQuery(query);
117 | System.out.println("ENAME");
118 | while (resultSet.next())
119 | System.out.println(resultSet.getNString("ENAME"));
120 | } else if (num == 6) {
121 | // Query 6
122 | query = queries[num - 1];
123 | assert paras.length == 1;
124 | System.out.println("Query " + num);
125 | query = query.replace(PARA_ENAME, paras[0]);
126 | resultSet = statement.executeQuery(query);
127 | System.out.println("ENAME\tDNAME");
128 | while (resultSet.next())
129 | System.out.println(resultSet.getNString("ENAME") + "\t" + resultSet.getNString("DNAME"));
130 | } else if (num == 7) {
131 | // Query 7
132 | query = queries[num - 1];
133 | assert paras.length == 2;
134 | System.out.println("Query " + num);
135 | query = query.replace(PARA_PNO + 1, paras[0]).replace(PARA_PNO + 2, paras[1]);
136 | resultSet = statement.executeQuery(query);
137 | System.out.println("ESSN");
138 | while (resultSet.next())
139 | System.out.println(resultSet.getNString("ESSN"));
140 | } else if (num == 8) {
141 | // Query 8
142 | query = queries[num - 1];
143 | assert paras.length == 1;
144 | System.out.println("Query " + num);
145 | query = query.replace(PARA_SALARY, paras[0]);
146 | resultSet = statement.executeQuery(query);
147 | System.out.println("DNAME");
148 | while (resultSet.next())
149 | System.out.println(resultSet.getNString("DNAME"));
150 | } else if (num == 9) {
151 | // Query 9
152 | query = queries[num - 1];
153 | assert paras.length == 1;
154 | System.out.println("Query " + num);
155 | query = query.replace(PARA_N, paras[0]);
156 | query = query.replace(PARA_HOURS, paras[1]);
157 | System.out.println("ENAME");
158 | resultSet = statement.executeQuery(query);
159 | while (resultSet.next())
160 | System.out.println(resultSet.getNString("ENAME"));
161 | }
162 |
163 |
164 | Objects.requireNonNull(resultSet).close();
165 |
166 | } else {
167 | System.out.println("Connection Failed, maybe mysql is close.");
168 | System.out.println("GoodBye~");
169 | }
170 | } catch (ClassNotFoundException | SQLException e) {
171 | // 处理JDBC错误 处理Class.forName错误
172 | e.printStackTrace();
173 | } finally {
174 | try {
175 | if (statement != null)
176 | statement.close();
177 | } catch (SQLException e) {
178 | e.printStackTrace();
179 | }
180 |
181 | try {
182 | if (connection != null)
183 | connection.close();
184 | } catch (SQLException e) {
185 | e.printStackTrace();
186 | }
187 | }
188 | } catch (ParseException e) {
189 | System.out.println(e.getMessage());
190 | formatter.printHelp("utility-name", options);
191 |
192 | System.exit(1);
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/lab_2/doc.tex:
--------------------------------------------------------------------------------
1 | \documentclass{ML}
2 |
3 | % 姓名,学号
4 | \infoauthor{朱明彦}{1160300314}
5 |
6 | % 课程类型,实验名称
7 | \infoexp{课程类型}{实验二}
8 |
9 | \infoschool{计算机学院}{高宏}
10 |
11 | \begin{document}
12 | \maketitle
13 |
14 | \tableofcontents
15 | \newpage
16 |
17 | \begin{center}
18 | \textbf{\zihao{3} 实验二 \ 使用高级语言操作MySQL数据库}
19 | \end{center}
20 | % 对于 3.1,粘贴 9 条 sql 语句的核心高级语言函数代码以及相应的查询结果,
21 | % 作为评分标准。先进行 3.2-3.5 的操作练习,结果无需截图。
22 | \section{实验目的}
23 | 学会使用高级语言访问 MySQL 数据库,并进行查询。
24 | \section{实验环境}
25 | \begin{itemize}
26 | \item Ubuntu 16.04.5; MySQL Ver 14.14 Distrib 5.7.25
27 | % \item MySQL Ver 14.14 Distrib 5.7.25
28 | \item Java version 1.8.0\_181; IDEA 2018.3.5
29 | % \item IntelliJ IDEA Ultimate 2018.3.5
30 | \end{itemize}
31 | \section{实验过程及结果}
32 | 实验中统一使用的命令行语句如下所示
33 | \begin{minted}{shell}
34 | java -cp /lib/java_lib/commons-cli-1.4.jar:\
35 | /lib/java_lib/mysql-connector-java-5.1.47.jar:\
36 | COMPANY_Query -q -p [Parameters]
37 | \end{minted}
38 | \begin{enumerate}
39 | \item \begin{minted}{Java}
40 | String PARA_PNO = "%PNO%";
41 | String query = "SELECT ESSN FROM WORKS_ON
42 | WHERE PNO = \"" + PARA_PNO + "\"";
43 | System.out.println("Query " + count);
44 | System.out.println("Please input pno:");
45 | String pno = cin.nextLine();
46 | query = query.replace(PARA_PNO, pno);
47 | resultSet = statement.executeQuery(query);
48 | System.out.println("ESSN");
49 | while (resultSet.next())
50 | System.out.println(resultSet.getNString("ESSN"));
51 | \end{minted}
52 | 当输入\texttt{\%PNO\%}为\texttt{P1}时, 实验结果如图\ref{fig:3.1}所示,由于结果过长,此处仅仅截取了部分结果。
53 | \begin{figure}[H]
54 | \centering
55 | \includegraphics[scale=0.4, bb=0 0 209 440]{media/3.1.eps}
56 | \caption{参加了项目编号为 \texttt{\%PNO\%} 的项目的员工姓名}\label{fig:3.1}
57 | \end{figure}
58 | \item \begin{minted}{Java}
59 | String PARA_PNAME = "%PNAME%";
60 | String query = "SELECT ENAME FROM EMPLOYEE, WORKS_ON, PROJECT
61 | WHERE EMPLOYEE.ESSN = WORKS_ON.ESSN
62 | AND PROJECT.PNO = WORKS_ON.PNO
63 | AND PROJECT.PNAME = \"" + PARA_PNAME + "\"";
64 | System.out.println("Query " + count);
65 | System.out.println("Please input pname:");
66 | String pname = cin.nextLine();
67 | query = query.replace(PARA_PNAME, pname);
68 | resultSet = statement.executeQuery(query);
69 | System.out.println("ENAME");
70 | while (resultSet.next())
71 | System.out.println(resultSet.getNString("ENAME"));
72 | \end{minted}
73 | 当输入\texttt{\%PNAME\%}为\texttt{SQL Project}时, 实验结果如图\ref{fig:3.2}所示.
74 | \begin{figure}[H]
75 | \centering
76 | \includegraphics[scale = 0.5, bb= 0 0 88 571]{media/3.2.eps}
77 | \caption{参加了项目名为\texttt{\%PNAME\%}的员工名字}\label{fig:3.2}
78 | \end{figure}
79 | \item \begin{minted}{Java}
80 | String PARA_DNAME = "%DNAME%";
81 | String query = "SELECT ENAME, ADDRESS FROM EMPLOYEE, DEPARTMENT
82 | WHERE EMPLOYEE.DNO = DEPARTMENT.DNO
83 | AND DEPARTMENT.DNAME = \"";
84 | System.out.println("Query " + count);
85 | System.out.println("Please input dname:");
86 | String dname = cin.nextLine();
87 | query = query.replace(PARA_DNAME, dname);
88 | resultSet = statement.executeQuery(query);
89 | System.out.println("ENAME");
90 | while (resultSet.next())
91 | System.out.println(resultSet.getNString("ENAME") +
92 | "\t" + resultSet.getNString("ADDRESS"));
93 | \end{minted}
94 | 当输入\texttt{\%DNAME\%}为\texttt{International Department}时, 实验结果如图\ref{fig:3.3}所示.
95 | \begin{figure}[H]
96 | \centering
97 | \includegraphics[scale = 0.5, bb= 0 0 465 392]{media/3.3.eps}
98 | \caption{在\texttt{\%PNAME\%}工作的所有工作人员的名字和地址}\label{fig:3.3}
99 | \end{figure}
100 | \item \begin{minted}{Java}
101 | String PARA_SALARY = "%SALARY%";
102 | String PARA_DNAME = "%DNAME%";
103 | String query = "SELECT ENAME, ADDRESS FROM EMPLOYEE, DEPARTMENT
104 | WHERE EMPLOYEE.DNO = DEPARTMENT.DNO
105 | AND DEPARTMENT.DNAME = \"" + PARA_DNAME + "\"
106 | AND SALARY < " + PARA_SALARY;
107 | System.out.println("Query " + count);
108 | System.out.println("Please input dname:");
109 | dname = cin.nextLine();
110 | System.out.println("Please input salary:");
111 | int salary = Integer.parseInt(cin.nextLine());
112 | query = query.replace(PARA_DNAME, dname)
113 | .replace(PARA_SALARY, String.valueOf(salary));
114 | resultSet = statement.executeQuery(query);
115 | System.out.println("ENAME\tADDRESS");
116 | while (resultSet.next())
117 | System.out.println(resultSet.getNString("ENAME") +
118 | "\t" + resultSet.getNString("ADDRESS"));
119 |
120 | \end{minted}
121 | 当输入\texttt{\%DNAME\%}为\texttt{International Department}, 输入\texttt{\%SALARY\%}为\texttt{4000}时, 实验结果如图\ref{fig:3.4}所示.
122 | \begin{figure}[H]
123 | \centering
124 | \includegraphics[scale = 0.5, bb= 0 0 471 310]{media/3.4.eps}
125 | \caption{在\texttt{\%DNAME\%}工作且工资低于\texttt{\%SALARY\%}的员工的名字和地址}\label{fig:3.4}
126 | \end{figure}
127 | \item \begin{minted}{Java}
128 | String PARA_PNO = "%PNO%";
129 | String query = "SELECT ENAME FROM EMPLOYEE
130 | WHERE ESSN NOT IN (
131 | SELECT DISTINCT ESSN
132 | FROM WORKS_ON
133 | WHERE WORKS_ON.PNO =\"" + PARA_PNO + "\")";
134 | System.out.println("Query " + count);
135 | System.out.println("Please input pno");
136 | pno = cin.nextLine();
137 | query = query.replace(PARA_PNO, pno);
138 | resultSet = statement.executeQuery(query);
139 | System.out.println("ENAME");
140 | while (resultSet.next())
141 | System.out.println(resultSet.getNString("ENAME"));
142 | \end{minted}
143 | 当输入\texttt{\%PNO\%}为\texttt{P2}时, 实验结果如图\ref{fig:3.5}所示.
144 | \begin{figure}[H]
145 | \centering
146 | \includegraphics[scale=0.4, bb=0 0 97 338]{media/3.5.eps}
147 | \caption{没有参加项目编号为\texttt{\%PNO\%}的项目的员工姓名}\label{fig:3.5}
148 | \end{figure}
149 | \item \begin{minted}{Java}
150 | String PARA_ENAME = "%ENAME%";
151 | String query = "SELECT ENAME, DNAME FROM EMPLOYEE, DEPARTMENT
152 | WHERE EMPLOYEE.DNO = DEPARTMENT.DNO
153 | AND EMPLOYEE.SUPERSSN IN (
154 | SELECT ESSN FROM EMPLOYEE
155 | WHERE ENAME = \"" + PARA_ENAME + "\")";
156 | System.out.println("Query " + count);
157 | System.out.println("Please input ename");
158 | String ename = cin.nextLine();
159 | query = query.replace(PARA_ENAME, ename);
160 | resultSet = statement.executeQuery(query);
161 | System.out.println("ENAME\tDNAME");
162 | while (resultSet.next())
163 | System.out.println(resultSet.getNString("ENAME") +
164 | "\t" + resultSet.getNString("DNAME"));
165 | \end{minted}
166 | 当输入\texttt{\%ENAME\%}为\texttt{张红}时, 实验结果如图\ref{fig:3.6}所示.
167 | \begin{figure}[H]
168 | \centering
169 | \includegraphics[scale=0.5, bb = 0 0 334 102]{media/3.6.eps}
170 | \caption{由\texttt{\%ENAME\%}领导的工作人员的姓名和所在的部门名字}\label{fig:3.6}
171 | \end{figure}
172 | \item \begin{minted}{Java}
173 | String PARA_PNO = "%PNO%";
174 | String query = "SELECT ESSN FROM WORKS_ON
175 | WHERE PNO = \"" + PARA_PNO + "1\"
176 | AND ESSN IN (
177 | SELECT ESSN FROM WORKS_ON
178 | WHERE PNO = \"" + PARA_PNO + "2\")";
179 | System.out.println("Query " + count);
180 | System.out.println("Please input pno1");
181 | pno = cin.nextLine();
182 | query = query.replace(PARA_PNO+1, pno);
183 | System.out.println("Please input pno2");
184 | pno = cin.nextLine();
185 | query = query.replace(PARA_PNO+2, pno);
186 | resultSet = statement.executeQuery(query);
187 | System.out.println("ESSN");
188 | while (resultSet.next())
189 | System.out.println(resultSet.getNString("ESSN"));
190 | \end{minted}
191 | 当输入\texttt{\%PNO1\%}为\texttt{P1}, \texttt{\%PNO\%}为\texttt{P2}时, 实验结果如图\ref{fig:3.7}所示.
192 | \begin{figure}[H]
193 | \centering
194 | \includegraphics[scale = 0.5, bb = 0 0 210 128]{media/3.7.eps}
195 | \caption{至少参加了项目编号为\texttt{\%PNO1\%}和\texttt{\%PNO2\%}的项目的员工号}\label{fig:3.7}
196 | \end{figure}
197 | \item \begin{minted}{Java}
198 | String PARA_SALARY = "%SALARY%";
199 | String query = "SELECT DNAME FROM EMPLOYEE, DEPARTMENT
200 | WHERE EMPLOYEE.DNO = DEPARTMENT.DNO
201 | GROUP BY DEPARTMENT.DNO
202 | HAVING AVG(SALARY) < " + PARA_SALARY;
203 | System.out.println("Query " + count);
204 | System.out.println("Please input salary:");
205 | salary = Integer.parseInt(cin.nextLine());
206 | query = query.replace(PARA_SALARY, String.valueOf(salary));
207 | resultSet = statement.executeQuery(query);
208 | System.out.println("DNAME");
209 | while (resultSet.next())
210 | System.out.println(resultSet.getNString("DNAME"));
211 | \end{minted}
212 | 当输入\texttt{\%SALARY\%}为\texttt{3000}时, 实验结果如图\ref{fig:3.8}所示.
213 | \begin{figure}[H]
214 | \centering
215 | \includegraphics[scale=0.5, bb=0 0 290 206]{media/3.8.eps}
216 | \caption{员工平均工资低于\texttt{\%SALARY\%}元的部门名称}\label{fig:3.8}
217 | \end{figure}
218 | \item \begin{minted}{Java}
219 | String PARA_N = "%N%";
220 | String PARA_HOURS = "%HOURS%";
221 | String query = "SELECT ENAME FROM EMPLOYEE, WORKS_ON
222 | WHERE EMPLOYEE.ESSN = WORKS_ON.ESSN
223 | GROUP BY EMPLOYEE.ESSN
224 | HAVING COUNT(PNO) >= " + PARA_N + "
225 | AND SUM(HOURS) <= " + PARA_HOURS; ;
226 | System.out.println("Query " + count);
227 | System.out.println("Please input n:");
228 | int n = Integer.parseInt(cin.nextLine());
229 | query = query.replace(PARA_N, String.valueOf(n));
230 | System.out.println("Please input hours:");
231 | int hours = Integer.parseInt(cin.nextLine());
232 | query = query.replace(PARA_HOURS, String.valueOf(hours));
233 | resultSet = statement.executeQuery(query);
234 | System.out.println("ENAME");
235 | while (resultSet.next())
236 | System.out.println(resultSet.getNString("ENAME"));
237 | \end{minted}
238 | 当输入\texttt{\%N\%}为\texttt{3}, 输入\texttt{\%HOURS\%}为\texttt{8}时, 实验结果如图\ref{fig:3.9}所示.
239 | \begin{figure}[H]
240 | \centering
241 | \includegraphics[scale = 0.5, bb=0 0 109 74]{media/3.9.eps}
242 | \caption{至少参加了\texttt{\%N\%}个项目且工作总时间不超过\texttt{\%HOURS\%}小时的员工名字}\label{fig:3.9}
243 | \end{figure}
244 | \end{enumerate}
245 | \section{实验心得}
246 | 本次实验可以选择使用不同的高级语言来完成, 此处用JAVA来完成实验, 相比使用C连接数据库, 仅仅需要将相应的\texttt{jar}包导入即可.
247 | 总的来说, 实验的难度不大.
248 | % \appendix
249 |
250 | % \section{源代码}
251 | % \section{参考文献}
252 | % \begin{thebibliography}{20}
253 | % % \bibitem{employee_name} 中国最常见名字前50名, \texttt{https://www.sohu.com/a/164406113\_367620}
254 | % \bibitem{employee_id} 身份证号在线生成器, \texttt{https://www.tinysoft.org/}
255 | % \end{thebibliography}
256 |
257 | \end{document}
258 |
--------------------------------------------------------------------------------
/lab_3/DreamHome_ER.tex:
--------------------------------------------------------------------------------
1 | \documentclass[12pt,landscape, a3paper]{article}
2 | % 使用12pt(对应于中文的小四号字)
3 | % \usepackage{xeCJK}
4 | % \setmainfont{Times New Roman}
5 | % \setCJKmainfont[BoldFont=Hei]{Hei}
6 | \usepackage{array,ragged2e,pst-node,pst-dbicons}
7 | \usepackage{ctex}
8 | \usepackage{geometry} %设置页边距的宏包
9 | \usepackage{titlesec} %设置页眉页脚的宏包
10 | \usepackage{amssymb}
11 | \usepackage{amsmath}
12 | \usepackage{tikz-er2}
13 | \usepackage{graphviz}
14 | \geometry{left=3.17cm,right=3.17cm,top=2.54cm,bottom=2.54cm} %设置 上、左、下、右 页边距
15 | \usetikzlibrary{positioning}
16 | \usetikzlibrary{shadows}
17 | \usetikzlibrary{arrows}
18 | \tikzstyle{every entity} = [top color=white, bottom color=blue!30,
19 | draw=blue!50!black!100, drop shadow]
20 | \tikzstyle{every weak entity} = [drop shadow={shadow xshift=.7ex,
21 | shadow yshift=-.7ex}]
22 | \tikzstyle{every attribute} = [top color=white, bottom color=yellow!20,
23 | draw=yellow, node distance=1cm, drop shadow]
24 | \tikzstyle{every relationship} = [top color=white, bottom color=red!20,
25 | draw=red!50!black!100, drop shadow]
26 | \tikzstyle{every isa} = [top color=white, bottom color=green!20,
27 | draw=green!50!black!100, drop shadow]
28 | \begin{document}
29 | \newpagestyle{main}{
30 | \sethead{哈尔滨工业大学}{Lab3-DreamHome\_ER\_Diagram}{1160300314 朱明彦} %设置页眉
31 | % \setfoot{左页脚}{中页脚}{右页脚} %设置页脚,可以在页脚添加 \thepage 显示页数
32 | \setfoot{}{}{\thepage}
33 | \headrule % 添加页眉的下划线
34 | % \footrule %添加页脚的下划线
35 | }
36 | \pagestyle{main} %使用该style
37 | % \setlength{\baselineskip}{15.6pt}
38 | % \setlength{\parskip}{0pt}
39 | % \renewcommand{\baselinestretch}{1.5}
40 | \begin{center}
41 | \scalebox{0.75}{
42 | \begin{tikzpicture}[node distance=1.5cm, every edge/.style={link}]
43 | \node[entity] (branch) {分公司};
44 | \node[attribute] (branch_number) [above right=of branch] {\key{公司编号}} edge (branch);
45 | \node[attribute] (branch_address) [right=of branch] {公司地址} edge (branch);
46 | \node[attribute] (branch_address_street) [right=of branch_address] {街道} edge (branch_address);
47 | \node[attribute] (branch_address_city) [above right=of branch_address] {城市} edge (branch_address);
48 | \node[attribute] (branch_address_postcode) [below right=of branch_address] {邮编} edge (branch_address);
49 | \node[multi attribute] (branch_telephone_number) [above left=of branch] {分公司电话号码} edge (branch);
50 |
51 | \node[relationship] (manager) [left=of branch] {经理} edge node [auto] {1} (branch);
52 | \node[attribute] (manager_start_date) [left=0.5cm of branch_telephone_number] {经理任职日期} edge (manager);
53 | \node[attribute] (manager_bouns) [below=0.5cm of manager_start_date] {经理奖金} edge (manager);
54 |
55 | \node[entity] (staff) [below left=of manager_bouns] {员工} edge node [auto] {1} (manager);
56 | \node[attribute] (staff_number) [above left=of staff] {\key{员工编号}} edge (staff);
57 | \node[attribute] (staff_gender) [left=of staff] {员工性别} edge (staff);
58 | \node[attribute] (staff_salary) [above=of staff] {员工工资} edge (staff);
59 | \node[attribute] (staff_name) [below=0.5cm of staff_gender] {员工名字} edge (staff);
60 | \node[attribute] (staff_position) [below =0.5cm of staff_name] {职位} edge (staff);
61 | % \node[attribute] (staff_branch) [below=0.5cm of staff_superior] {所在分公司编号} edge (staff);
62 |
63 | \node[relationship] (charge) [below=of staff] {负责} edge node[auto] {1} (staff);
64 |
65 | \node[relationship] (staff_work_in) [right=of staff] {在} edge node [auto] {m} (staff);
66 | \draw[thick] (staff_work_in) -- node[auto] {1} (branch);
67 | \node[attribute] (staff_superior) [below=0.5cm of staff_work_in] {主管名字} edge (staff);
68 | % \node[relationship] (staff_superior) [below right=of staff] {主管} edge node [auto] {1} (staff);
69 | % \draw[edge] (staff) -- node[auto] {m} (staff_superior);
70 |
71 | \node[entity] (property) [below=of charge] {出租的房产} edge node [auto] {m} (charge);
72 | \node[attribute] (property_number) [above left=of property] {\key{房产编号}} edge (property);
73 | \node[attribute] (property_type) [left=of property] {房产类型} edge (property);
74 | \node[attribute] (number_of_rooms) [below=0.3cm of property_type] {房间数量} edge (property);
75 | \node[attribute] (property_address) [below=0.5cm of number_of_rooms] {地址} edge (property);
76 | \node[attribute] (property_address_street) [above left=of property_address] {街道} edge (property_address);
77 | \node[attribute] (property_address_city) [left=of property_address] {城市} edge (property_address);
78 | \node[attribute] (property_address_postcode) [below left=of property_address] {邮编} edge (property_address);
79 | \node[attribute] (monthly_rent) [below right=of property] {每月租金} edge (property);
80 | % \node[attribute] (owner_numebr) [below right=of property] {业主编号} edge (property);
81 |
82 | \node[relationship] (have) [below=of property] {有} edge node [auto] {m} (property);
83 |
84 | \node[entity] (property_owners) [below=of have] {业主} edge node[auto] {1} (have);
85 | \node[attribute] (property_owners_number) [right=of property_owners] {\key{业主编号}} edge (property_owners);
86 | \node[attribute] (property_owners_name) [above right=of property_owners] {名字} edge (property_owners);
87 | \node[attribute] (property_owners_address) [above left=of property_owners] {地址} edge (property_owners);
88 | \node[attribute] (property_owners_telephone) [left=of property_owners] {电话} edge (property_owners);
89 |
90 | \node[isa] (owners_type) [below=of property_owners] {x};
91 | \draw[double, thick] (property_owners) -- (owners_type);
92 | \node[entity] (private_owners) [below left=of owners_type] {私人业主};
93 | \draw[double, thick] (private_owners) -- (owners_type);
94 | \node[entity] (business_owners) [below right=of owners_type] {企业业主};
95 | \draw[double, thick] (business_owners) -- (owners_type);
96 | \node[attribute] (business_owners_type) [below left=of business_owners] {企业类型} edge (business_owners);
97 | \node[attribute] (business_owners_contact) [below right=of business_owners] {联系人姓名} edge (business_owners);
98 |
99 | \node[attribute] (newspaper_name) [right=of property_owners_number] {\key{报纸名字}};
100 | \node[entity] (newspaper) [right=of newspaper_name] {报纸} edge (newspaper_name);
101 | \node[attribute] (newspaper_address) [above right=of newspaper] {地址} edge (newspaper);
102 | \node[attribute] (newspaper_telephone) [above left=of newspaper] {电话} edge (newspaper);
103 | \node[attribute] (newspaper_contact) [right=of newspaper] {联系人姓名} edge (newspaper);
104 |
105 | \node[relationship] (carry) [below=of newspaper] {刊登} edge node [auto] {1} (newspaper);
106 | \node[weak entity] (advertisement) [below=of carry] {广告} edge node [auto] {m} (carry);
107 | \node[attribute] (ad_property_numebr) [below left=of advertisement] {\discriminator{房产编号}} edge (advertisement);
108 | \node[attribute] (ad_date) [below=of advertisement] {\discriminator{广告日期}} edge (advertisement);
109 | \node[attribute] (ad_rent) [below right=of advertisement] {广告费用} edge (advertisement);
110 |
111 |
112 | \node[relationship] (property_viewing) [below=of manager] {看房};
113 | \node[attribute] (property_viewing_date) [right=of property_viewing] {看房日期} edge (property_viewing);
114 | \node[attribute] (property_viewing_comment) [above right=of property_viewing] {评论} edge (property_viewing);
115 | \draw[thick] (property_viewing) -- node [above] {n} (property);
116 | \node[relationship] (leases) [below=of property_viewing] {租约};
117 | \draw[thick] (leases) -- node [auto] {1} (property);
118 | \node[attribute] (leases_monthly_rent) [below left=of leases] {每月租金} edge (leases);
119 | \node[attribute] (leases_method_of_payment) [below=0.5cm of leases_monthly_rent] {付款方式} edge (leases);
120 | \node[attribute] (leases_deposit) [below=of leases] {定金} edge (leases);
121 | \node[attribute] (leases_number) [below right=of leases] {\key{租期编号}} edge (leases);
122 | \node[attribute] (leases_deposit_whether) [below=0.5cm of leases_number] {定金是否支付} edge (leases);
123 | \node[attribute] (leases_start_date) [above left=of leases] {租约始期} edge (leases);
124 | \node[attribute] (leases_end_date) [above=0.5cm of leases] {租约终期} edge (leases);
125 | \node[attribute] (leases_duration) [above right=of leases] {租约时长} edge (leases);
126 |
127 | \node[entity] (client) [right=5cm of leases] {客户};
128 | \node[attribute] (client_name) [right=of client] {客户名字} edge (client);
129 | \node[attribute] (client_number) [above=0.5cm of client_name] {\key{客户编号}} edge (client);
130 | \node[attribute] (client_telephone) [below=0.5cm of client_name] {电话号码} edge (client);
131 | \node[attribute] (client_accomodation_type) [below=of client] {喜欢的住所类型} edge (client);
132 | \node[attribute] (client_max_rent) [above=of client] {最多可支付租金} edge (client);
133 |
134 | \draw[thick] (client) -- node [above] {m} (property_viewing);
135 | \draw[thick] (client) -- node [auto] {1} (leases);
136 | % \node[entity] (customer) {顾客};
137 | % \node[attribute] (cname) [above=of customer] {姓名} edge (customer);
138 | % \node[attribute] (cid) [above left=of customer] {\key{社会安全号码}} edge (customer);
139 | % \node[attribute] (c_tel) [above right=of customer] {电话} edge (customer);
140 |
141 | % \node[relationship] (have) [below=of customer] {拥有} edge node[auto] {1} (customer);
142 | % \node[entity] (address) [below=of have] {地址} edge node[auto] {m} (have);
143 | % \node[attribute] (state) [left=of address] {\key{州名}} edge (address);
144 | % \node[attribute] (city) [above left=of address] {\key{城市}} edge (address);
145 | % \node[attribute] (street) [below left=of address] {\key{街道}} edge (address);
146 | % \node[multi attribute] (telephone) [below=of address] {电话} edge (address);
147 |
148 | % \node[entity] (telephone) [below=of have] {电话} edge node[auto] {n} (have);
149 | % \node[attribute] (telephone_number) [below=of telephone] {\key{电话号码}} edge (telephone);
150 |
151 | % \node[relationship] (own) [right=of have] {持有} edge node[auto] {1} (customer);
152 | % \node[entity] (account) [below=of own] {账户} edge node[auto] {n} (own);
153 |
154 | % \node[attribute] (acc_id) [above right=of account] {\key{号码}} edge (account);
155 | % \node[attribute] (type) [right=of account] {类型} edge (account);
156 | % \node[attribute] (incomde) [below right=of account] {收支情况} edge (account);
157 | % \node[isa] (isa) [below=1cm of emp] {ISA} edge (emp);
158 |
159 | % \node[entity] (mec) [below left=1cm of isa] {Mechanic} edge (isa);
160 | % \node[entity] (sal) [below right=1cm of isa] {Salesman} edge (isa);
161 |
162 | % \node[relationship] (does) [left=of mec] {Does} edge (mec);
163 |
164 | % \node[weak entity] (rep) [below=of does] {RepairJob} edge (does);
165 | % \node[attribute] (rnum) [left=of rep] {\discriminator{Number}} edge (rep);
166 | % \node[attribute] (desc) [above left=of rep] {Description} edge (rep);
167 | % \node[attribute] (cost) [below left=of rep] {Cost} edge (rep);
168 | % \node[attribute] (mat) [left=0.5cm of cost] {Parts} edge (cost);
169 | % \node[attribute] (work) [below left=0.5cm of cost] {Work} edge (cost);
170 |
171 | % \node[ident relationship] (reps) [below=of rep] {Repairs} edge [total] (rep);
172 |
173 | % \node[entity] (car) [right=of reps] {Car} edge [<-] (reps);
174 | % \node[attribute] (lic) [above=of car] {\key{License}} edge (car);
175 | % \node[attribute] (mod) [below=of car] {Model} edge (car);
176 | % \node[attribute] (year) [below right=of car] {Year} edge (car);
177 | % \node[attribute] (manu) [below left=1.5cm of car] {Manufacturer} edge (car);
178 |
179 | % \node[relationship] (buy) [below=of sal] {Buys};
180 | % \node[attribute] (pri) [above left=of buy] {Price} edge (buy);
181 | % \node[attribute] (sdate) [left=of buy] {Date} edge (buy);
182 | % \node[attribute] (bval) [below left=of buy] {Value} edge (buy);
183 |
184 | % \node[relationship] (sel) [right=of buy] {Sells};
185 | % \node[attribute] (sdate) [above right=of sel] {Date} edge (sel);
186 | % \node[derived attribute] (sval) [right=of sel] {Value} edge (sel);
187 | % \node[attribute] (com) [below right=of sel] {Comission} edge (sel);
188 |
189 | % \draw[link] (car.10) -| (buy) (buy) edge (sal);
190 | % \draw[link] (car.-10) -| (sel) (sel) |- (sal);
191 |
192 | % \node[entity] (cli) [below right=0.5cm and 3.7cm of car] {Client};
193 | % \node[attribute] (cid) [right=of cli] {\key{ID}} edge (cli);
194 | % \node[attribute] (cname) [below left=of cli] {Name} edge (cli);
195 | % \node[multi attribute] (cphone) [below right=of cli] {Phone} edge (cli);
196 | % \node[attribute] (cadd) [below=of cli] {Address} edge (cli);
197 |
198 | % \draw[link] (cli.70) |- node [pos=0.05, auto, swap] {buyer} (sel);
199 | % \draw[link] (cli.110) |- node [pos=0.05, auto] {seller} (buy);
200 |
201 | \end{tikzpicture}
202 | }
203 | \end{center}
204 |
205 | \end{document}
--------------------------------------------------------------------------------
/homework_2/homework_2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,a4paper]{article}
2 | % 使用12pt(对应于中文的小四号字)
3 | % \usepackage{xeCJK}
4 | % \setmainfont{Times New Roman}
5 | % \setCJKmainfont[BoldFont=Hei]{Hei}
6 | \usepackage{ctex}
7 | \usepackage{geometry} %设置页边距的宏包
8 | \usepackage{titlesec} %设置页眉页脚的宏包
9 | \usepackage{amssymb}
10 | \usepackage{amsmath}
11 | \usepackage{minted}
12 | \geometry{left=3.17cm,right=3.17cm,top=2.54cm,bottom=2.54cm} %设置 上、左、下、右 页边距
13 | \begin{document}
14 | \newpagestyle{main}{
15 | \sethead{哈尔滨工业大学}{数据库系统\_第二次作业}{1160300314 朱明彦} %设置页眉
16 | % \setfoot{左页脚}{中页脚}{右页脚} %设置页脚,可以在页脚添加 \thepage 显示页数
17 | \setfoot{}{}{\thepage}
18 | \headrule % 添加页眉的下划线
19 | % \footrule %添加页脚的下划线
20 | }
21 | \pagestyle{main} %使用该style
22 |
23 | % \setlength{\baselineskip}{15.6pt}
24 | \setlength{\parskip}{0pt}
25 | \renewcommand{\baselinestretch}{1.5}
26 |
27 | \paragraph{一、}
28 | \begin{enumerate}
29 | \item[1)]
30 | \begin{minted}{SQL}
31 | SELECT CNAME, TEACHER
32 | FROM S, C, SC
33 | WHERE S.S# = SC.S# AND C.C# = SC.C# AND S.S# = "003";
34 | \end{minted}
35 | \item[2)]\begin{minted}{SQL}
36 | SELECT DISTINCT SNAME
37 | FROM S, C, SC
38 | WHERE S.S# = SC.S# AND C.C# = SC.C# AND S.AGE = "男"
39 | AND C.TEACHER = "程军";
40 | \end{minted}
41 | \item[3)]\begin{minted}{SQL}
42 | SELECT CNAME
43 | FROM C
44 | WHERE CNAME NOT IN(
45 | SELECT DISTINCT CNAME
46 | FROM S, C, SC
47 | WHERE S.S# = SC.S# AND C.C# = SC.C# AND S.SNAME = "刘丽";
48 | )
49 | \end{minted}
50 | \item[4)]\begin{minted}{SQL}
51 | SELECT S#, SNAME
52 | FROM S, SC
53 | WHERE S.S# = SC.S#
54 | GROUP BY S.S# HAVING AVG(GRADE) < 60;
55 | \end{minted}
56 | \textbf{注意此处的问题,在使用了\texttt{GROUP BY}子句后,\texttt{SELECT}子句的列名表中只能出现分组属性和聚集函数;从而,因为
57 | 因为此处需要\texttt{S\#, SNAME},从而在分组时应该同时选择\texttt{S\#, SNAME},修改后的SQL语句如下:}
58 | \begin{minted}{SQL}
59 | SELECT S#, SNAME
60 | FROM S, SC
61 | WHERE S.S# = SC.S#
62 | GROUP BY S.S# S.SNAME HAVING AVG(GRADE) < 60;
63 | \end{minted}
64 | \item[5)]\begin{minted}{SQL}
65 | SELECT S#
66 | FROM S, SC
67 | WHERE S.S# = SC.S#
68 | GROUP BY S.S# HAVING COUNT(*) >= 3
69 | ORDER BY S# ASC;
70 | \end{minted}
71 | \end{enumerate}
72 |
73 | \paragraph{二、}
74 | \begin{enumerate}
75 | \item[1)]\begin{minted}{SQL}
76 | CREATE TABLE Classes
77 | (
78 | class CHAR(20) PRIMARY KEY,
79 | type CHAR(2) NOT NULL,
80 | country CHAR(15),
81 | numGuns SMALLINT,
82 | bore, SMALLINT,
83 | displacement, INT
84 | );
85 | \end{minted}
86 |
87 | \begin{minted}{SQL}
88 | CREATE TABLE Ships
89 | (
90 | name CHAR(20) PRIMARY KEY,
91 | class CHAR(20),
92 | launched SMALLINT,
93 | FOREIGN KEY (class) REFERENCES Classes(class)
94 | );
95 | \end{minted}
96 |
97 | 注意
98 | \begin{itemize}
99 | \item 在插入\texttt{Classes}时,主键\texttt{class}可以唯一区分实体;
100 | \item 在插入\texttt{Ships}时,主键\texttt{name}可以唯一区分实体,并且外键\texttt{class}需要存在。
101 | \end{itemize}
102 | \item[2)]\begin{itemize}
103 | \item[a.]\begin{minted}{SQL}
104 | INSERT
105 | INTO Classes
106 | VALUES("Nelson", "bb", "Gt.Britain", 9, 16, 34000);
107 |
108 | INSERT
109 | INTO Ships
110 | VALUES("Nelson", "Nelson", 1927);
111 |
112 | INSERT
113 | INTO Ships
114 | VALUES("Rodney", "Nelson", 1927);
115 | \end{minted}
116 | \item[b.]\begin{minted}{SQL}
117 | DELETE
118 | FROM Ships
119 | WHERE name IN
120 | (
121 | SELECT
122 | FROM Ships, Outcomes
123 | WHERE Ships.name = Outcomes.ship
124 | AND Outcomes.result = "sunk"
125 | );
126 | \end{minted}
127 | \item[c.]\begin{minted}{SQL}
128 | UPDATE Classes
129 | SET bore = bore * 2.5;
130 |
131 | UPDATE Classes
132 | SET displacement = displacement / 1.1;
133 | \end{minted}
134 | \end{itemize}
135 | \item[3)]\begin{minted}{SQL}
136 | CREATE VIEW (class, type, numGuns, bore, displacement, launched)
137 | AS
138 | SELECT class, type, numGuns, bore, displacement, launched
139 | FROM Classes, Ships
140 | WHERE Classes.class = Ships.ship
141 | AND country = "Gt.Britain";
142 | \end{minted}
143 | \item[4)]\begin{minted}{SQL}
144 | SELECT battle
145 | FROM Ships, Outcomes
146 | WHERE Ships.name = Outcomes.ship
147 | AND Ships.class = "Kongo";
148 | \end{minted}
149 | \item[5)]\begin{minted}{SQL}
150 | SELECT AVG(numGuns)
151 | FROM Classes
152 | WHERE type = "bb";
153 | \end{minted}
154 | \textbf{注意此处的问题应该是,所有的主力舰的火炮数量加和然后平均,改正后的SQL语句如下:}
155 | \begin{minted}{SQL}
156 | SELECT AVG(numGuns)
157 | FROM Classes, Ships
158 | WHERE Classes.class = Ships.class AND Classes.type = "bb";
159 | \end{minted}
160 | \item[6)]\begin{minted}{SQL}
161 | SELECT MIN(launched)
162 | FROM Classes, Ships
163 | WHERE Classes.class = Ships.class
164 | GROUP BY Classes.class;
165 | \end{minted}
166 | \textbf{注意需要同时显示类名和下水年份,修改后的SQL语句如下:}
167 | \begin{minted}{SQL}
168 | SELECT Classes.class, MIN(launched)
169 | FROM Classes, Ships
170 | WHERE Classes.class = Ships.class
171 | GROUP BY Classes.class;
172 | \end{minted}
173 | \item[7)]
174 | \textbf{下面这种写法存在问题,对于没有船沉没但是有超过3艘船的类型,没有输出!}
175 | \begin{minted}{SQL}
176 | SELECT class, COUNT(result)
177 | FROM Ships, Outcomes
178 | WHERE Ships.name = Outcomes.ship
179 | AND Outcomes.result = "sunk"
180 | AND class IN
181 | (
182 | SELECT class
183 | FROM Ships, Outcomes
184 | WHERE Ships.name = Outcomes.ship
185 | GROUP BY class HAVING COUNT(*) >= 3
186 | )
187 | GROUP BY class;
188 | \end{minted}
189 | \textbf{应该改为如下写法,注意不使用where过滤是否沉船条件:}
190 | \begin{minted}{SQL}
191 | SELECT class, SUM(case 1 when Outcomes.result = "sunk" else 0 end)
192 | FROM Ships, Outcomes
193 | WHERE Ships.name = Outcomes.ship
194 | AND class IN
195 | (
196 | SELECT class
197 | FROM Ships, Outcomes
198 | WHERE Ships.name = Outcomes.ship
199 | GROUP BY class HAVING COUNT(*) >= 3
200 | )
201 | GROUP BY class;
202 | \end{minted}
203 | \item[8)]\begin{minted}{SQL}
204 | SELECT name
205 | FROM Ships
206 | UNION
207 | SELECT ship
208 | FROM Outcomes;
209 | \end{minted}
210 | \item[9)]\begin{minted}{SQL}
211 | SELECT country
212 | FROM Classes
213 | GROUP BY country HAVING COUNT(type) >= 2;
214 | \end{minted}
215 | \item[10)]\begin{minted}{SQL}
216 | SELECT country
217 | FROM Classes
218 | WHERE numGuns >= ALL
219 | (
220 | SELECT numGuns
221 | FROM Classes
222 | );
223 | \end{minted}
224 | \item[11)]\begin{minted}{SQL}
225 | SELECT Classes.class
226 | FROM Classes, Ships, Outcomes
227 | WHERE Classes.class = Ships.class
228 | AND Ships.name = Outcomes.ship
229 | AND Outcomes.result = "sunk"
230 | GROUP BY Classes.class HAVING COUNT(*) >= 1;
231 | \end{minted}
232 | \end{enumerate}
233 | \paragraph{三、}
234 | \begin{enumerate}
235 | \item[1)]\begin{minted}{SQL}
236 | CREATE TABLE Orders
237 | (
238 | OrderID CHAR(20) PRIMARY KEY,
239 | SupplierID CHAR(20),
240 | MovieID CHAR(20),
241 | Copies INT,
242 | FOREIGN KEY (SupplierID) REFERENCES Suppliers(SupplierID),
243 | FOREIGN KEY (MovieID) REFERENCES Movies(MovieID)
244 | );
245 |
246 | CREATE TABLE Rentals
247 | (
248 | CustomerID CHAR(20),
249 | TapeID CHAR(20),
250 | CkoutDate DATE,
251 | Duration INT,
252 | PRIMARY KEY (CustomerID, TapeID, CkoutDate),
253 | FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID),
254 | FOREIGN KEY (TapeID) REFERENCES Inventory(TapeID)
255 | );
256 | \end{minted}
257 | \item[2)]\begin{enumerate}
258 | \item[a.]\begin{minted}{SQL}
259 | INSERT
260 | INTO Rentals
261 | VALUES("9823", "5600", 2017-03-26, 30);
262 | \end{minted}
263 | \end{enumerate}
264 | \item[b.]\begin{minted}{SQL}
265 | DELETE
266 | FROM Rentals
267 | WHERE CkoutDate < '2000-01-01';
268 | \end{minted}
269 | \item[c.]\begin{minted}{SQL}
270 | UPDATE MovieSupplier
271 | SET Price = Price / 6.88;
272 | \end{minted}
273 | \item[3)]\begin{minted}{SQL}
274 | CREATE VIEW JHV_Suppliers (MovieName, Price)
275 | AS
276 | SELECT MovieName, Price
277 | FROM Movies, Suppliers, MovieSupplier
278 | WHERE Movies.MovieID = MovieSupplier.MovieID
279 | AND Suppliers.SupplierID = MovieSupplier.SupplierID
280 | AND Suppliers.SupplierName = "Joe's House of Video";
281 | \end{minted}
282 | \item[4)]\begin{minted}{SQL}
283 | SELECT SupplierName, COUNT(MovieID)
284 | FROM Inventory, Suppliers, MovieSupplier
285 | WHERE Inventory.MovieID = MovieSupplier.MovieID
286 | AND Suppliers.SupplierID = MovieSupplier.SupplierID
287 | GROUP BY Suppliers.SupplierID;
288 | \end{minted}
289 | \item[5)]\begin{minted}{SQL}
290 | SELECT MovieName
291 | FROM Orders, Movies
292 | WHERE Movies.MovieID = Orders.MovieID
293 | AND SUM(Orders.Copies) > 5
294 | GROUP BY Orders.MovieID;
295 | \end{minted}
296 | \item[6)]\begin{minted}{SQL}
297 | SELECT MovieName
298 | FROM Inventory, Movies
299 | WHERE Movies.MovieID = Inventory.MovieID
300 | GROUP BY Movies.MovieID HAVING COUNT(TapeID) > 1;
301 | \end{minted}
302 | \item[7)]\begin{minted}{SQL}
303 | SELECT MovieName
304 | FROM Movies, Inventory, Rentals
305 | WHERE Movies.MovieID = Inventory.MovieID
306 | AND Rentals.TapeID = Inventory.TapeID
307 | AND Rentals.Duration >= ALL
308 | (
309 | SELECT Duration
310 | FROM Rentals
311 | );
312 | \end{minted}
313 | \item[8)]\begin{minted}{SQL}
314 | SELECT DISTINCT MovieName
315 | FROM Movies
316 | WHERE MovieName NOT IN(
317 | SELECT DISTINCT MovieName
318 | FROM Movies, Inventory
319 | WHERE Movies.MovieID = Inventory.MovieID;
320 | )
321 | \end{minted}
322 | \item[9)]\begin{minted}{SQL}
323 | SELECT SupplierID, SupplierName
324 | FROM Suppliers, MovieSupplier
325 | WHERE Suppliers.SupplierID = MovieSupplier.MovieID
326 | AND MovieSupplier.MovieID IN
327 | (
328 | SELECT MovieID
329 | FROM Movies
330 | WHERE MovieName = "Hacksaw Ridge"
331 | )
332 | AND MovieSupplier.Price <= ALL
333 | (
334 | SELECT Price
335 | FROM Movies, MovieSupplier
336 | WHERE Movies.MovieID = MovieSupplier.MovieID
337 | AND Movies.MovieName = "Hacksaw Ridge"
338 | );
339 | \end{minted}
340 | \item[10)]\begin{minted}{SQL}
341 | SELECT CustomerName
342 | FROM Movies, Rentals, Inventory, Customers
343 | WHERE Movies.MovieID = Inventory.MovieID
344 | AND Rentals.TapeID = Inventory.TapeID
345 | AND Customers.CustomerID = Rentals.CustomerID
346 | AND Movies.MovieName = "Beauty and the Beast"
347 | UNION
348 | SELECT CustomerName
349 | FROM Rentals, Inventory, MovieSupplier, Suppliers, Customers
350 | WHERE Rentals.CustomerID = Customers.CustomerID
351 | AND Inventory.TapeID = Rentals.TapeID
352 | AND MovieSupplier.SupplierID = Suppliers.SupplierID
353 | AND Inventory.MovieID = MovieSupplier.MovieID
354 | AND Inventory.MovieID IN
355 | (
356 | SELECT MovieID
357 | FROM MovieSupplier, Suppliers
358 | WHERE MovieSupplier.SupplierID = Suppliers.SupplierID
359 | AND Suppliers.SupplierName = "VWS Video"
360 | );
361 | \end{minted}
362 | \end{enumerate}
363 |
364 |
365 | \end{document}
--------------------------------------------------------------------------------
/Paper_Summary/doc.tex:
--------------------------------------------------------------------------------
1 | \documentclass{ML}
2 | \usepackage{amssymb}
3 | \usepackage{latexsym}
4 | % 姓名,学号
5 | \infoauthor{朱明彦}{1160300314}
6 |
7 | % 课程类型,实验名称
8 | \infoexp{课程类型}{概述}
9 |
10 | \infoschool{计算机学院}{高宏}
11 |
12 | \begin{document}
13 | \maketitle
14 |
15 | \tableofcontents
16 | \newpage
17 |
18 | \begin{center}
19 | \textbf{\zihao{3} 论文概述}
20 | \end{center}
21 |
22 | \section{解决的问题}
23 | 选择的论文\cite{toain}为2018年PVLDB上面的一篇文章,\textbf{主要解决的问题是Road Networks上面动态的kNN查询,论文编号35}。
24 |
25 | 针对这个问题,作者主要有如下\textbf{三个方面}的工作:
26 | \begin{enumerate}
27 | \item 对于Road Networks上需要进行kNN查询的系统建立新的数学模型,并找到其中影响系统整体吞吐量的关键因素。
28 | \item 建立了一个以Shortcut Graph为基础的索引,SCOB。
29 | \item 设计了可以根据Update/Query的所用时间动态调整SCOB以最大化系统吞吐量的算法,TOAIN。
30 | \end{enumerate}
31 | \section{采用的思想}
32 | 作者为了解决Road Networks上面动态的kNN查询,采用的思想是\textbf{先明确系统的目标(最大化系统的吞吐量),建立数学模型衡量寻找影响体统吞吐量的关键因素,对于关键的因素建立索引并利用设计的算法尽量提高关键因素影响下的部分,最终实现最大化吞吐量的目的}。
33 |
34 | \begin{figure}[htb]
35 | \centering
36 | \includegraphics[width=0.8\linewidth]{media/notations.png}
37 | \caption{Notations}\label{fig:notations}
38 | \end{figure}
39 | \subsection{数学模型方面}
40 | 作者主要考虑了两种不同的情况,分别对应于现实中两种不同的应用,即\textbf{如滴滴类似的打车软件系统和捕捉精灵球的Pokemon}。 作者在考虑数学模型时,从\textbf{Query}和\textbf{Update}分别考虑其影响,然后针对这两种不同的应用区分它们在Query和Update上面的差别,从而建立起来不同的数学模型。
41 |
42 | \textbf{以下两种应用都假设所有的查询到来是随机的,论文中为了方便假设Query符合泊松过程(Poisson Process)。}
43 | \subsubsection{打车软件(BUA+QF Model)}\label{sec:bua_qf}
44 | \textbf{BUA(Batch Update Arrival)模型是针对Update操作来说},其假设所有的元素都会进行Update操作,且都是在时间片的开始时刻进行,如果在某一个时间片里没有完成相应的Update操作,则直接舍弃未做操作,进行下一轮操作即可。\textbf{QF(Query First)是针对系统中队列模型来说的},其假设Query在队列中的优先级高于Update。
45 |
46 | 基于上面的假设,在打车软件这样的系统中,对于每个Query是来自用户的,查询在其附近最近的K个车辆;每个Update是来自汽车的,其在指定间隔内向系统返回其最新的位置。这样,高优先级的Query可以尽量减少用户请求的查询的延迟,并且丢失少量Update使得某些车辆的信息具有很短距离的差距,所以这样的假设对于该应用是合理的。
47 |
48 | 利用在\cite{single-server-queue}中的结论,可以得到式\eqref{equ:1},其中$R_q$为平均查询响应时间,$t_q, V_{q}$分别是查询时间的期望和方差,$\lambda_{q}$为Query到达的速率,即泊松过程中的参数。
49 | \begin{equation}
50 | R_{q}=\frac{\lambda_{q}\left(t_{q}^{2}+V_{q}\right)}{2\left(1-\lambda_{q^{t} q}\right)}+t_{q}
51 | \label{equ:1}
52 | \end{equation}
53 |
54 | 通过式\eqref{equ:1}可以看到,\textbf{整体的查询响应时间随$\lambda_{q}$的增大而增大,这也与我们的直觉相符合,说明此模型具有一定的道理}。进而通过两个约束,\textbf{查询的响应时间不能超过用户能够忍受的最大值}和\textbf{在一个时间间隔内需要最少的用于Update的时间限制},得到最终的$\lambda_{q}$的上界,如式\eqref{eq:2}所示。
55 |
56 | \begin{equation}
57 | \lambda_{q}^{*} \leq \min \left\{\frac{2\left(R_{q}^{*}-t_{q}\right)}{V_{q}+2 R_{q}^{*} t_{q}-t_{q}^{2}}, \quad\left(T-m t_{u}\right) /\left(T \cdot t_{q}\right)\right\}
58 | \label{eq:2}
59 | \end{equation}
60 |
61 | 为了可解释性,将式\eqref{eq:2}转化为式\eqref{eq:3}。
62 | \begin{equation}
63 | \lambda_{q}^{*} \leq \left\{
64 | \begin{array}{lll}
65 | {1 / t_{q},} & {\text { if } \alpha \beta<1 / 2} & {(\text { QoS-bound mode })} \\
66 | {(1-\beta) / t_{q},} & {\text { if } \alpha \beta \geq 1 / 2} &\text {(Update-bound mode)}
67 | \end{array}
68 | \right.
69 | \label{eq:3}
70 | \end{equation}
71 |
72 | 其中$\alpha=R_{q}^{*} / t_{q} ; \quad \beta=m t_{u} / T ; \quad \gamma=V_{q} / t_{q}^{2}$;$\alpha$用来衡量平均查询相应时间的上界与平均查询时间的比值,$\beta$用来衡量一个时间片内处理Update所用时间的占比,$\gamma$是离散系数(coefficient of variation)的平方,相对于标准差其为无量纲量可以用在不同的索引算法中进行比较,一般$\gamma \in [0.1, 0.9]$。
73 |
74 | \subsubsection{Pokemon游戏(RUA+FCFS模型)}
75 | 对于pokemon类似的以所在位置为中心,查询周围存在的Pokemon,并进行捕捉的这类游戏,其Update不是按照某一指定的时间间隔返回的,而是随机的,所以其Update操作不能在使用BUA模型,而是转为RUA(Random Update Arrival)模型,同样的为了方便研究,\textbf{作者假设RUA的Update符合另一个泊松过程(与Query到来的泊松过程不同)}。
76 |
77 | 对于Query的优先级,Pokemon游戏很注重每个Pokemon的位置更新,所以该模型的队列模型使用了FCFS(First-come-first-served),即Query和Update具有相同的优先级,根据到来的顺序来进行操作。
78 |
79 | 其分析过程与\ref{sec:bua_qf}节类似,最终得到式\eqref{eq:rua_fcfs},衡量在该模型下的Query到来频率的上界。
80 |
81 | \begin{equation}
82 | \lambda_{q}^{*} \leq \min \left\{\frac{2\left(R_{q}^{*}-t_{q}\right)\left(1-\lambda_{u} t_{u}\right)-\lambda_{u}\left(V_{u}+t_{u}^{2}\right)}{V_{q}+2 R_{q}^{*} t_{q}-t_{q}^{2}}, \frac{1-\lambda_{\mathrm{u}} t_{u}}{t_{q}}\right\}
83 | \label{eq:rua_fcfs}
84 | \end{equation}
85 |
86 | \subsection{索引SCOB方面}
87 |
88 | \subsubsection{假设条件}\label{sec:assumptions}
89 | 在索引和算法方面,作者做出了两个假设,分别是:
90 | \begin{enumerate}
91 | \item 抽象后的图G是无向图
92 | \item 所有节点的Rank是不一样的
93 | \end{enumerate}
94 |
95 | %这两个假设虽然在后面进行了放松,但本质上论文作者最终解决的问题也没有彻底摆脱这第一个假设的约束,这一部分在后面%TODO
96 | %详细来说。
97 |
98 | \subsubsection{符号定义}
99 | \paragraph{SHORTCUT SET $SC_{<}$}\label{para:shortcut_set} 给定一个图$G=(V, E)$和一个定义在$V \to \mathbb{N}$上的Rank Function,则一条捷径(shortcut)$u \curvearrowright v \in SC_{<}$当且仅当1.$u, v \in V$,2.$r(u) < r(v)$,3.对于从$u$到$v$上最短路上的中间任意节点$z$均有$r(z) < r(u)$。
100 |
101 | 从上面的定义我们可以直接得到一个结论,如式\eqref{lemma:3},其中$SC_{<}$是从$G$上导出的捷径图(shortcut graph),因为不一定所有的$G$上的最短路都符合$r(z) < r(u)$即上述定义的第3条规则。
102 | \begin{equation}
103 | d_{G}(u, v) \leq d_{SC_{<}}(u, v) \quad \forall u, v \in V
104 | \label{lemma:3}
105 | \end{equation}
106 | \paragraph{SUMMIT NODE}
107 | 给定一个最短路径(shortest path)$s \leadsto t$,则对于该最短路的Summit Node是$s \leadsto t$上具有最高权重的节点。
108 |
109 | 根据$SC_{<}$和summit node的定义以及第一个假设,我们可以直接得到式\eqref{lemma:4},其中$x$是最短路径$s \leadsto t$上的summit node。
110 | \begin{equation}
111 | d_{G}(s, t)=d_{SC_{<}}(s, x)+d_{SC_{<}}(t, x)
112 | \label{lemma:4}
113 | \end{equation}
114 | \paragraph{DOWNHILL OBJECTS}
115 | 论文中作者为了形象表示不同节点的rank不同,具有越高rank的节点在图中的位置越高,如图\ref{fig:downhill}所示。基于这种形象的表示,如果在$SC_{<}$中有一条从$v$指向$u$的shortcut,则称$v$是$u$的downhill object。
116 | \begin{figure}[htb]
117 | \centering
118 | \includegraphics[width=0.6\linewidth]{media/downhill.png}
119 | \caption{Downhill Objects Example}\label{fig:downhill}
120 | \end{figure}
121 | \paragraph{$\mathbf{kDNNs}$}
122 | 给定一个节点$u \in G$,离它最近的k个downhill objects被记作$kDNN(u)$。
123 |
124 | \subsubsection{基本思想}\label{sec:scob_basic}
125 | 根据式\eqref{lemma:3}和$G$是无向图的假设,可以有结论\textit{给定一个节点$s$和一个位于节点$t$的物体$o$,如果$o$是$s$的kNN之一,则有$o \in kDNN(x)$,$x$是最短路$s \leadsto t$上的summit node}(其证明使用了证明其逆否命题的方法,主要利用三角不等式、式\eqref{lemma:3}进行放缩)。\textbf{通过以上结论,可以利用kDNN和一些特定的summit node可以得到一些源点的KNN结果。}
126 |
127 | SCOB索引本质上也是利用了Dijkstra在图上进行搜索,而传统的方式对于一个有M个节点的图,需要进行M次s-climb(从源点到summit node的搜索)以及M次t-climb(从目标点到summit node的搜索);而使用了SCOB索引\textbf{在每个summit node上记录在Shortcut Graph中的k个最近的downhill objects的id和其距离,以减少s-climb(t-climb)的次数,来提高效率,最终实现了仅需要从Query发出的节点进行一次s-climb就可以找到对应这次Query的kNN结果}。
128 |
129 | 具体如何维护SCOB索引,见\ref{sec:scob_index}节。
130 |
131 | \subsubsection{假设条件放松}\label{sec:assumptions_release}
132 | 对\ref{sec:assumptions}节提到的两个假设,论文中分别进行了放松。对于第一个假设,其仅仅提到了一些做法,但在实际中可能并不适用,具体解释见\ref{sec:shortcoming}节。
133 |
134 | 对于第二个假设,作者修改了\ref{para:shortcut_set}节中shortcut的定义,其中第2点改为$r(u) \leq r(v)$,进而将如此导出的图记为$SC_{\leq}$。进而称在$SC_{<}$上的climb为straight climb,而在$SC_{\leq}$上的climb为gentle climb。
135 | \subsection{算法TOAIN方面}
136 | \subsubsection{符号定义}\label{sec:toain_def}
137 | \paragraph{COVER NODES, COVER DIMENSION}
138 | 将Road Network放在二维空间上的地图,然后利用$K \times K$个方格将其分成$K^2$个cell,对于给定的cell $C$,其外面有$3 \ times 3$和$5 \times 5$的邻居,则对于处在$C$的节点$u$,如果$u \leadsto v$必须穿过$3 \times 3$的邻居,其中在最短路径上且跨过边界的边$(x, y)$,那么称$x$为$C$的一个Cover Node,所有这样的Cover Node的数量称为Cover Dimension。\textbf{例子见\ref{sec:example_cover_nodes}节说明}。
139 |
140 | \subsubsection{基本思想}
141 | TOAIN能够通过调整Rank function来调整SCOB索引的参数,寻找Query和Update之间的折中,进而达到最大化吞吐量的目的。所以\textbf{TOAIN的主要思想就是如何确定更合理的Rank Function,使得越重要的顶点具有越高的Rank}。具体的算法描述见\ref{sec:toain_compute_rank}节所示。
142 | \section{基本算法描述}
143 | 文中以伪代码形式讲述的算法共有4个,下面将分别进行描述。
144 | \subsection{SCOB Index}\label{sec:scob_index}
145 | \subsubsection{Query}
146 | \begin{figure}[htb]
147 | \centering
148 | \includegraphics[width=0.6\linewidth]{media/query.png}
149 | \caption{Query Algorithm}\label{fig:query}
150 | \end{figure}
151 | 在SCOB索引上进行kNN查询,主要是利用从查询所在的节点开始Dijkstra算法,对于每一个遇到的节点利用其kDNN更新最终的结果集合$\mathcal{R}$,直到遍历完所有节点或者$\mathcal{R}$中已有k个节点且当前遇到的节点在$SC_{<}$中的距离已经超过$\mathcal{R}$中的最大距离停止。算法如图\ref{fig:query}所示。
152 |
153 | \textbf{由于其利用的是Dijkstra从原点进行搜索,所以其复杂度为$O(k|V|log|V|)$}。
154 | \subsubsection{Insert}
155 | \begin{figure}[htb]
156 | \centering
157 | \includegraphics[width=0.6\linewidth]{media/insert.png}
158 | \caption{Insert Algorithm}\label{fig:insert}
159 | \end{figure}
160 | 对于插入一个物体$o$,则进行从$o$所在节点$t$的Dijkstra算法,更新所有中间经过的节点的kDNN集合。算法如图\ref{fig:insert}所示。
161 |
162 | \textbf{复杂度同样是Dijkstra的复杂度,即$O(|V|log|V|)$}。
163 | \subsubsection{Delete}
164 | \begin{figure}[htb]
165 | \centering
166 | \includegraphics[width=0.6\linewidth]{media/delete.png}
167 | \caption{Delete Algorithm}\label{fig:delete}
168 | \end{figure}
169 | 删除一个物体$o$,则需要首先判断该物体是否在其所在节点的kDNN集合中,如果不在算法直接结束;否则,需要从该顶点进行Dijkstra算法,对所有经过且kDNN包含物体$o$的节点,将$o$从其对应的kDNN集合中删除,并且对于所有上述节点补充新的物体进入kDNN集合。算法如图\ref{fig:delete}所示。
170 |
171 | \textbf{复杂度为$O(|V|log|V| + |V||E|)$}。
172 |
173 | \textbf{对于系统中涉及到的Update操作,没有直接给出相应的算法,而是改为用一次Insert和一次Delete操作进行代替。}
174 | \subsection{TOAIN}\label{sec:toain_compute_rank}
175 | \subsubsection{Compute Rank}
176 | \begin{figure}[htb]
177 | \centering
178 | \includegraphics[width=0.6\linewidth]{media/compute_rank.png}
179 | \caption{Compute Rank Algorithm}\label{fig:compute_rank}
180 | \end{figure}
181 | 根据\ref{sec:toain_def}节的定义,可以有结论\textbf{较大Cell对应的Cover Nodes具有较高的重要性,且较高重要性的Cover Nodes应具有较高的Rank}。
182 |
183 | 所以如图\ref{fig:compute_rank}所示的算法,先初始化所有的顶点rank为0,然后从1到h开始循环,较大的K逐步利用Dijkstra搜索进行更新遇到节点的rank值,同时不断减小K。
184 |
185 | \textbf{由于每次K对半分,所以Dijkstra经过的节点数目不超过$O(\zeta^*)$(Cover Dimension的上限),所以整体的复杂度为$O(h\zeta^*|V|log|V|)$}
186 |
187 | \subsubsection{climb}\label{sec:climb}
188 | 对于TOAIN下面的climb,每次所经过的节点不会超过$h\zeta^*$个,根据上一节的分析显然成立,所以进行一次climb的时间复杂度为$O(h\zeta^*)$。
189 |
190 | \section{结论}
191 | 根据\ref{sec:scob_basic}节,文中提出的算法针对每一次Query仅需一次s-climb,而根据\ref{sec:climb}可知每次climb的复杂度不超过$O(h\zeta^*)$,每一次Query时间复杂度为$O(h\zeta^*)$。调整$h$可以调整Query和Update之间的时间,从而达到最大化吞吐量的目的。
192 |
193 | 根据\cite{zeta-most},$\zeta^*$不会很大,所以Computer Rank实际的复杂度接近$O(|V|log|V|)$。
194 |
195 | 最后根据论文中的实验结果,也侧面证实了其在相关算法中,无论对于实际例子还是生成数据,无论是BUA+QF模型还是RUA+FCFS模型,SCOB和TOAIN都是用时最少的。
196 | \section{举例说明}
197 | \subsection{COVER NODES, COVER DIMENSION}\label{sec:example_cover_nodes}
198 | 如图\ref{fig:cover_nodes}所示,对于给定的Cell $C$,位于其中的节点$u$,其$3\times3, 5 \times 5$的邻居均在图中标出。其中对于$u$与任何节点的最短路而言,其均需要通过$i, d, o$中的一个才可以到达,而$(u, d), (u, i), (u, o)$均跨过了$C$的边界,所以$i, d, o$均为Cover Nodes,且$C$的Cover Dimension为3。
199 |
200 | \begin{figure}[htb]
201 | \centering
202 | \includegraphics[width=0.7\linewidth]{media/cover_nodes.png}
203 | \caption{Cover Nodes example}\label{fig:cover_nodes}
204 | \end{figure}
205 |
206 | \subsection{COMPUTER RANK}
207 | 如图\ref{fig:example loop 1}所示,初始化$K=10$,$h=2$,图中所有的蓝色标记表示一个节点,红色数字表示该节点的rank值,橙色线段表示边,黑色方框表示Grid。
208 | \begin{figure}[htb]
209 | \centering
210 | \includegraphics[width=0.7\linewidth]{media/example-1.jpg}
211 | \caption{Loop 1}\label{fig:example loop 1}
212 | \end{figure}
213 |
214 | \textbf{可以看到,在初始化的第一次循化会将所有节点的Rank都更新为1,此时的$S$仍然包含所有的节点。}
215 |
216 | 进入第二轮循环,此时$K$被更新为5,所有的Dijkstra算法都不会超过其对应的最小的$5 \times 5$的Grid。所有cover nodes的权值被更新为2,如图\ref{fig:example loop 2}所示。
217 | \begin{figure}[htb]
218 | \centering
219 | \includegraphics[width=0.7\linewidth]{media/example-2.jpg}
220 | \caption{Loop 2}\label{fig:example loop 2}
221 | \end{figure}
222 |
223 | 由于继续更新,$K$会小于5,而此时与循环中需要对其所在的$5 \times 5$的Grid进行Dijkstra算法,所以$K$不够大导致算法停止,最终结果如图\ref{fig:example loop 2}所示。\textbf{可以看到,最终Rank值较大的节点,也是具有较高连通度的节点,这与使用\textit{betweenness centrality}进行rank赋值,具有相似性,说明了此算法的合理性}。
224 | \section{算法的不足}\label{sec:shortcoming}
225 | 在论文中,作者提出放松\ref{sec:assumptions}节中第一个假设的方式,是针对将有向图的所有边均取反,这种做法可能导致整体计算Shortcut Graph时间复杂度变化,并且在现实中确实\textbf{存在单行线},如果简单对其取反可能缺少实际的物理意义,继而可能引入并不存在的边导致实际距离估计偏差较大的问题,如存在最短路径$s \leadsto t$,且$x$为其上的summit node,而此时$d_{SC_{<}}(t, x) \neq d_{SC_{<}}(x, t)$,进而导致式\eqref{lemma:4}不成立。
226 |
227 | 在相关的实验中,作者也没有进行关于Road Network中真正存在单向边,无法将其转化为无向图处理的情况提供相应的实验数据,也侧面说明了在这一部分TOAIN和SCOB结合起来对于存在大量单向边的情况处理有所困难。
228 | \section{改进方法}
229 | 由于SCOB索引和TOAIN算法设计的非常精巧,如果简单的想做基于这个索引的改进,会破坏掉其上面的性质,导致时间复杂度的变化较大,所以很抱歉我没有想到较好的改进方法。
230 | \section{相关工作(小综述)}
231 | 使用Dijkstra算法进行kNN查询,从查询q所在的节点开始进行Dijkstra算法,直到有k个最近的物体被搜索到即可。这样没有维护索引的需要,但对于
232 |
233 | ROAD\cite{ROAD}同样是基于Dijkstra算法,但是主要是针对物体在network上面稀疏分布的情况。主要思想是将大图划分成若干个小图(文中称为Rnets),然后在利用Dijkstra搜索时如果某个小图(Rnet)中没有物体,则关于这个小图的搜索就被跳过。\cite{ROAD}中主要使用的两类索引,Route Overlay和Association Directory,其中前者维护物理上的network结构包括shortcut,后者用来维护物体到节点、边以及Rnets的映射。其基本结构如图\ref{fig:ROAD}所示。
234 | \begin{figure}[htb]
235 | \centering
236 | \includegraphics[width=0.8\linewidth]{media/ROAD.png}
237 | \caption{ROAD framework}\label{fig:ROAD}
238 | \end{figure}
239 |
240 | G-Tree\cite{G-tree}也是建立了子图的层次结构,但是每个子图都与一个Occurrence-List关联,利用OL按照ID降序记录子图的层次结构。在G树上预计算并记录了基础节点之间的最短距离,然后通过这些基础点之间的距离和图的层次结构再计算其余节点之间的最短距离。也因为其记录了更多的信息,所以在G树上查询很快,但更新较慢。G树的基本结构如图\ref{fig:G-tree}所示。在G-Tree上进行KNN查询的时间复杂度为$\mathcal{O}\left(\tau \log \tau+\log _{2}^{2} f \cdot \log _{f} \frac{|\mathcal{V}|}{\tau} \cdot|\mathcal{V}|\right)$,其中$\tau$为每个叶节点最多含有的顶点数目。
241 |
242 | \begin{figure}[htb]
243 | \centering
244 | \includegraphics[width=0.9\linewidth]{media/g-tree.png}
245 | \caption{G-Tree Example}\label{fig:G-tree}
246 | \end{figure}
247 |
248 | V树\cite{V-tree}采用与G树类似的层次结构,如图\ref{fig:V-tree}所示。V树标识位于子图边界的边界节点。通过维护这些边界节点的最近对象列表,设计了有效的技术来回答kNN查询。
249 |
250 | \begin{figure}[htb]
251 | \centering
252 | \includegraphics[width=0.9\linewidth]{media/v-tree.png}
253 | \caption{V-Tree Example}\label{fig:V-tree}
254 | \end{figure}
255 |
256 | 以上这些论文是比较新的针对在Road Network上动态的KNN查询的问题进行的,并且当前也是效率比较高的。除此之外还有一些比较久远的论文(大约在2005年左右的),效率没有很高,但是还有一定的参考价值。
257 |
258 | \cite{IER}提出的是一个针对空间网络(并非完全的路径距离,而是欧式距离的限制)上通用查询的网络,将输入的网络生成一个图模型(Modeling Graph),并将其按照三种分量进行存储,邻接分量(adjacency component),network R-tree以及poly-line分量,如图\ref{fig:ier}所示。在执行KNN查询时,使用的是IER(Incremental Euclidean Restriction),通过多轮用于高维相似性检索来实现kNN,即先假设做1-NN,再逐步放松距离至实现kNN。
259 |
260 | \begin{figure}
261 | \centering
262 | \includegraphics[width=0.6\linewidth]{media/IER}
263 | \caption{IER example}
264 | \label{fig:ier}
265 | \end{figure}
266 |
267 | \cite{DisBrw}提出的是通过预计算在图上所有可能点之间的最短距离,然后编码从u到其余节点的最短路径,并将其分到多个子图中。利用Shortest Path Quadtree这个数据结构来维护最短距离,如图\ref{fig:disbrw}所示,想找到s到d的最短路径,从s对应的子树查询到去d需要经过t的区域,然后获得t的子树直到可以在子树中找到d即可。与其类似的利用预计算图上的最短距离的做法还有\cite{voronoi},不过其使用的数据结构为Voronoi Diagram。
268 | \begin{figure}
269 | \centering
270 | \includegraphics[width=0.7\linewidth]{media/DisBrw}
271 | \caption{Shortest Path Quadtree example}
272 | \label{fig:disbrw}
273 | \end{figure}
274 |
275 |
276 | \appendix
277 |
278 | % \section{源代码}
279 | % \section{参考文献}
280 | \begin{thebibliography}{20}
281 | \bibitem{toain} Luo, S., Kao, B., Li, G., Hu, J., Cheng, R., \& Zheng, Y. (2018). TOAIN: a throughput optimizing adaptive index for answering dynamic k NN queries on road networks. Proceedings of the VLDB Endowment, 11(5), 594-606.
282 | \bibitem{single-server-queue} J. W. Cohen. The single server queue, volume 8. Elsevier, 2012.
283 | \bibitem{zeta-most}S. Luo, R. Cheng, X. Xiao, B. Kao, S. Zhou, and J. Hu. Fast
284 | matching of detour routes and service areas. Technical
285 | Report TR-2016-03, The University of Hong Kong, 2016.
286 | \bibitem{ROAD}K. C. Lee, W.-C. Lee, B. Zheng, and Y. Tian. Road: A new
287 | spatial object search framework for road networks. TKDE,
288 | 24(3):547–560, 2012.
289 | \bibitem{G-tree}R. Zhong, G. Li, K.-L. Tan, L. Zhou, and Z. Gong. G-tree:
290 | An efficient and scalable index for spatial search on road
291 | networks. TKDE, 27(8):2175–2189, 2015.
292 | \bibitem{V-tree}B. Shen, Y. Zhao, G. Li, Q. Y. Zheng, Weimin, B. Yuan, and
293 | Y. Rao. V-tree: Efficient knn search on moving objects with
294 | road-network constraints. In ICDE, pages 871–882, 2016.
295 | \bibitem{IER} D. Papadias, J. Zhang, N. Mamoulis, and Y. Tao. Query
296 | processing in spatial network databases. In PVLDB, pages
297 | 802–813, 2003.
298 | \bibitem{DisBrw} H. Samet, J. Sankaranarayanan, and H. Alborzi. Scalable
299 | network distance browsing in spatial databases. In SIGMOD,
300 | pages 43–54, 2008.
301 | \bibitem{voronoi} M. Kolahdouzan and C. Shahabi. Voronoi-based k
302 | nearest neighbor search for spatial network databases.
303 | In Proceedings of VLDB, pages 840–851, 2004.
304 | \end{thebibliography}
305 |
306 | \end{document}
307 |
--------------------------------------------------------------------------------