首页 > 其他分享 >CSCI235 – Database Systems

CSCI235 – Database Systems

时间:2024-10-29 18:42:40浏览次数:5  
标签:index CSCI235 file Database Systems statement queries relational SELECT

CSCI235 – Database Systems

2024 S4

Implementation Task 2

Due on 7 November 2024

Scope

The Implementation of Task 2 is related to the contents of topic on Indexing.

This Implementation is due by Thursday, 7 November 2024, 9:00 pm Singapore time. This task is worth 3% of the total assessment for the subject.

Only electronic submission through Moodle at: https://moodle.uowplatform.edu.au/   is accepted. All email submission will be deleted and mark 0 (“zero”) will be awarded.

For all the  implemented tasks,  your  report  or output  must  include  a  listing  of all PL/pgPGSQL statements processed.

The submission procedure is explained at the end of this specification.

Specification

Step 1

If you have not done it yet, download the TPCHR sample database and load the sample TPCHR using user account tpchr. This will make the user account tpchr the owner of the TPCHR database.

Step 2

In this step we shall use the relational tables included in a sample TPCHR benchmark database owned by the user tpchr. The conceptual schema of the sample database is included in the file tpchr.pdf.

Instructions for Creating and Executing a psql Script. to Capture Queries and Output

Step 1: Create Your Script. File

1. Write your SQL commands :

o  Use any text editor (e.g., Notepad, VS Code) to create a script. file containing the SQL commands you want to execute.

2. Save the script:

o  Save the file with a .sql extension (e.g., my_script.sql).

Step 2: Execute the Script in psql and Capture Output

1. Open the psql command prompt:

o  Launch the psql command-line interface for PostgreSQL.

2.  Run the script. and capture both queries and output:

o  To execute your script. file and capture both the SQL queries and their output, use the following command:

psql -U tpchr -e -f my_script.sql > output_file.txt

o  Explanation :

   -U: login as user tpchr

   -e: Enables query echo, displaying each SQL command before execution.

   -f: Specifies the script. file to execute.

   > : Redirects both queries and output to a specified output file (e.g., output_file.txt).

This will create output_file.txt containing both the SQL queries and their results.

Task 1 (1.8 marks)

The objective of this task is to find the smallest number of indexes that improve performance of a given collection of SELECT statements. We do not expect the best possible improvement in performance for each SELECT statement, however, processing of each SELECT statement must benefit from the existence of at least one of the indexes. An important objective is to minimize the total number of indexes created.

Using the relational table LINEITEM of the sample database TPCHR, for each one of the queries listed below:

i.     Find all the discount (l_discount) of all the items that are shipped (l_shipdate) most recently. Hint. Most recently mean the latest shipment date.

ii.     Find the total number of items shipped by air (l_shipmode) in 1998 (l_shipdate).

iii.     Find the order number (l_orderkey) and item number (l_linenumber) that have the highest discount (l_discount).

iv.     Find the total number of item per line status (l_linestatus). List the line status and the total items per line status.

v.     Find the order key (l_orderkey), line item number (l_linenumber), line status  (l_linestatus), shipment date (l_shipdate) and shipment mode (l_shipmode) of  all orders with the order number (l_orderkey) 1795718, 1799046, and 1794626.

a) Construct a PGSQL statement that produces the required output specified in the statement.               (0.5 mark)

b) Find the smallest number of indexes that improve代 写CSCI235 – Database Systems  performance of a given collection of SELECT statements of a relational table LINEITEM. The smallest number of indexing means a database system will compute the five queries constructed in (a) using one or more indexes that you have created. Hint, you may create an index that can be used to compute more than one queries. Use the explain analyse statement to justify your solutions.                                                            (1.3 mark)

Deliverables

A file solution1.pdf with CREATE INDEX statements that improve the performance of the queries listed (i, ii, iii, iv, and v above) and the execution plan generated.

Please remember that you must consider each one of the queries as an individual case! Please remember that all relational tables are large enough to make full table scans more time consuming that accessing the tables through an index! It means that any solution in which an index is not used for query processing is incorrect.

Task 2 (1.2 marks)

The objective of this task is to implement queries statements that processing of each SELECT statement will traverse the index according to specified manners listed in the task.

The implementation task is to use the database tables found in the TPCHR workbench.

Consider the following index is created for the ORDERS relational table:

ordersIdx(o_custkey, o_clerk, o_orderdate)

For each of the select statements specified below, find the best possible queries that when the queries are executed, the queries will traverse the index ordersIdx in a manner described in the specification (i) to (vi) .

Note: You need to write a 、create index’statement to create the index describe above before implementing your solutions.

i.     Write a SELECT statement such that when it is executed, the query must traverse the index ordersIdx vertically, and the execution MUST access the relational table ORDERS.                      (0.2 mark)

ii.     Write a SELECT statement such that when it is executed, the query must traverse the  index vertically, and  the  execution  MUST NOT access  the  relational  table ORDERS.                          (0.2 mark)

iii.     Write a SELECT statement such that when it is executed, the query must traverse the index vertically and then horizontally at the leaf level of the index and the execution MUST access the relational table ORDERS.          (0.2 mark)

iv.     Write a SELECT statement such that when it is executed, the query must traverse the  index vertically and then horizontally at  the  leaf  level  of the  index  and execution MUST NOT access the relational table ORDERS.                     (0.2 mark)

v.     Write a SELECT statement such that when it is executed, the query must traverse the index horizontally at the leaf level of the index and the execution MUST access to the relational table ORDERS.                                    (0.2 mark)

vi.     Write a SELECT statement such that when it is executed, the query must traverse the index horizontally at the leaf level of the index and the execution MUST NOT access to the relational table ORDERS.                                                      (0.2 mark)

Deliverables

Submit a file solution.lst with a report from processing of pgSQL script. solution.sql. The report MUST have no errors the report MUST list all pgSQL statements processed. The report MUST include ONLY the ‘Create index’ statement, ‘SELECT’ statements, ‘ Explain analyze’ statement that implement the specifications of the implementation task.

Submissions

This assignment is due by 9:00 pm (21:00 hours) Thursday, 7 November 2024, 9:00 pm Singapore time.

Zip the files solution.sql and solution.pdf and submit the zipped file through Moodle in the following way:

1)  Access Moodle at http://moodle.uowplatform.edu.au/

2)  To login use a Login link located in the right upper corner the Web page or in the middle of the bottom of the Web page

3)   When  successfully  logged  in,  select  a  site  CSCI235  (SP424)  Database Systems

4)   Scroll down to a section Submissions of Implementation Tasks

5)   Click at Submit your Implementation Task 1 here link.

6)   Click at a button Add Submission

7)   Move the solution.pgSQL and solution.lst (or the zipped file) into an area provided in Moodle. You can drag and drop files here to add them. You can also use a link Add…

8)   Click at a button Save changes,

9)   Click at check box to confirm authorship of a submission,

10) When you  are  satisfied,  remember  to  click  at  a  button  Submit assignment.

标签:index,CSCI235,file,Database,Systems,statement,queries,relational,SELECT
From: https://www.cnblogs.com/CSSE2310/p/18514150

相关文章

  • pg系数据库经典报错,no pg_hba.conf entry for host “x.x.x.x“, user “xxx“, datab
            上一篇文档述说了pg的一个经典报错“currenttransactionisaborted,commandsignoreduntilendoftransactionblock”【经典报错1】,这次再来述说一个pg系数据的经典报错。        pg系数据库指的是postgre、greenplum、国产数据中的kingbase、g......
  • [MySQL#1] database概述 | 常见的操作指令 | MySQL架构 | 存储引擎
    #1024程序员节|征文#目录一.数据库概念0.连接服务器1.什么是数据库口语中的数据库为什么数据不直接以文件形式存储,而需要使用数据库呢?总结二.......
  • PbootCMS打开后提示读取数据库文件失败: Unable to open database
    问题表现打开PbootCMS时提示“读取数据库文件失败:Unabletoopendatabase”。原因数据库文件没有读写权限。解决方法设置文件夹权限:将 data 文件夹设置为777权限。同时将 config、static、runtime、data 文件夹设置为可读写权限。注意事项备份文件......
  • PbootCMS出现database disk image is malformed的解决办法
    databasediskimageismalformed 错误通常是由于SQLite数据库文件损坏引起的。这种问题可能发生在写入数据库时突然中断操作,比如服务器突然重启或网络中断等情况。以下是一些解决方法,包括删除栏目模型重建和修复SQLite数据库。解决方法1.删除栏目模型,重建备份数据库......
  • MIT-OC Electrochemical Energy Systems4-1
    四、输运现象L16浓度极化目录浓度极化的背景线性扩散与对流2.1费克定律2.2分子随机游走与扩散系数2.3质量守恒与对流扩散方程极限电流密度3.1浓度极化的三种基本机制3.2极限电流的定义3.3极限电流密度的推导固体氧化物燃料电池实例4.1电池反应及稳态扩散4.2......
  • MIT-OC Electrochemical Energy Systems 3-4
    三、反应动力学L15离子吸附与嵌入目录中性物质的表面吸附与嵌入1.1平衡态1.1.1Langmuir等温线1.1.2Frumkin等温线1.2动力学1.2.1标准吸附动力学1.2.2过渡态模型1.2.2.1仅考虑排斥体积的模型1.2.2.2考虑相互作用的模型吸附/嵌入过程中的法拉第反应2.1......
  • CS 551 Systems Programming
    CS551SystemsProgramming,Fall2024ProgrammingProject1Out:10/13/2024Sun.Due:10/26/2024Sat.23:59:59Inthisprojectyouraregoingtoimplementacustommemorymanagerthatmanagesheapmemoryallocationatprogramlevel.Herearethereasonswh......
  • 启动service报错ORA-44317: database open read-only
    ADG(RAC)备库环境,srvctl添加service服务成功,启动service时报错ORA-44317:databaseopenread-only。这是预期行为,使用“srvctladdservice-d<db_name>-s<service_name>”创建服务时,将在OCR中创建和注册服务,但在使用“srvctlstartservice-d<db_name>-s<service_n......
  • 出现WrongArgumentException: Malformed database URL, failed to parse the connecti
    目录1.问题所示2.原理分析3.解决方法1.问题所示编辑数据源的时候,后端出现如下BugThelastpacketsentsuccessfullytotheserverwas0millisecondsago.Thedriverhasnotreceivedanypacketsfromtheserver.com.mysql.cj.jdbc.exceptions.Com......
  • CS 520: Introduction to Operating Systems
    CS520:IntroductiontoOperatingSystemsHomeworkAssignment#3Thisassignmentissomewhatopen-ended—startworkingonitassoonasyoucan!Areminder:Youmayworkingroups;however,youmaynotshowanyoneyourcodeorcopyofanypartofanyonee......