Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

运行指南

目录结构

  • answer 包含代码模板,根据题干,你需要在相应的文件中填写你的答案。
  • public-test 是一组公开的测试,包含几个测试脚本:
    • data 包含导入数据的脚本;
    • test 包含测试脚本。

详细用法见测试部分。

准备

  1. 该目录打开终端(你可以在 VSCode 中打开终端,或在 。确保工作目录是该目录,因为 source 将用到相对路径)
  2. 使用 mysql -u root -p 登录 MySQL
  3. 进入 MySQL 后,先选择一个数据库:
create database testdb;
use testdb;

编写答案

仔细阅读 PDF 中的题目要求,然后在 answer 中的对应文件填写你的代码。对于每个文件,务必保持原有格式,只在注释的地方填写代码。

测试

以下测试脚本仅用于临时测试,原理是对比某些列、对比查询结果的条数等,不代表最后的测试。

每个测试会有若干测试用例,如通过则显示 PASS,不通过则显示 FAIL

有能力的同学,还可以修改测试代码来帮助调试。如果你对 SQL 代码不够了解,建议直接按照以下步骤测试你的代码。

测试 1、2 题

用法

source public-test/data/load-data-1,2.sql
source answer/scene-1.sql
source public-test/test/scene-1-test.sql
source answer/scene-2.sql
source public-test/test/scene-2-test.sql

输出

scene-1-test.sql 包含 1 个测试用例,检查 BigCustomerNormalCustomer 表中的内容,测试通过将输出:

+-------------------+
| CHECK BigCustomer |
+-------------------+
| PASS              |
+-------------------+

+----------------------+
| CHECK NormalCustomer |
+----------------------+
| PASS                 |
+----------------------+

scene-2-test.sql 包含 1 个测试用例,测试添加索引后存储过程快了多少倍(前提是上一个测试通过)。测试通过将输出:

+------------------+---------------+---------------+----------------------+
| time_before / ms | time_now / ms | speed_up_rate | CHECK index efficacy |
+------------------+---------------+---------------+----------------------+
|       13884.8810 |     1164.3290 |       11.9252 | PASS                 |
+------------------+---------------+---------------+----------------------+

测试第 3 题

用法

source public-test/data/load-data-3,4,5.sql
source answer/scene-3.sql
source public-test/test/scene-3-test.sql

输出

scene-3-test 包含 2 个测试用例,分别检查已交付未交付订单被删除后的用户余额和产品库存。

对于已交付订单,测试通过将输出:

+---------------------------------+------------------------------+
| CHECK filled - customer balance | CHECK filled - product stock |
+---------------------------------+------------------------------+
| PASS                            | PASS                         |
+---------------------------------+------------------------------+

对于未交付订单,测试通过将输出:

+-----------------------------------+--------------------------------+
| CHECK unfilled - customer balance | CHECK unfilled - product stock |
+-----------------------------------+--------------------------------+
| PASS                              | PASS                           |
+-----------------------------------+--------------------------------+

测试第 4.1、4.2 题

用法

这里直接以 root 身份给 Alice 授权,然后检查授权。

source public-test/data/load-data-3,4,5.sql
source answer/scene-4.1.sql
source public-test/test/scene-4.1-test.sql
source answer/scene-4.2.1.sql
source answer/scene-4.2.2.sql
source answer/scene-4.2.3.sql
source public-test/test/scene-4.2-test.sql

输出

scene-4.1-test 包含 1 个测试用例,检查审计表中新插入的一条记录。测试通过将输出:

+-------------+
| CHECK audit |
+-------------+
| PASS        |
+-------------+

运行 scene-4.2.3.sql 后将直接输出一行审计日志,请直接查看,此处不再测试。

scene-4.2-test 包含 1 个测试用例,检查 SalesManagerAlice 的权限数量。测试通过将输出:

+-----------------------------------+----------------------------+
| CHECK num of priv of SalesManager | CHECK num of priv of Alice |
+-----------------------------------+----------------------------+
| PASS                              | PASS                       |
+-----------------------------------+----------------------------+

测试第 5 题

用法

source public-test/data/load-data-3,4,5.sql
source answer/scene-5.sql
source public-test/test/scene-5-test.sql

输出

scene-5-test 包含 6 个测试用例,分别检查不同条件下事务运行的结果。以下为各用例通过的输出:

用例 1:未交付,库存不足(此题使用 TRIGGER 触发了扣取库存失败的错误)

+------------------------------+--------+
| TEST CASE                    | RESULT |
+------------------------------+--------+
| Case 1: [Unfilled] low stock | PASS   |
+------------------------------+--------+

用例 2:未交付,库存充足,无优惠券,余额与信用不足

+-----------------------------------------------------------------------------+--------+
| TEST CASE                                                                   | RESULT |
+-----------------------------------------------------------------------------+--------+
| Case 2: [Unfilled] enough stock; no coupon; insufficient balance and credit | PASS   |
+-----------------------------------------------------------------------------+--------+

用例 3:未交付,库存充足,有优惠券但打折后仍然不足,余额与信用不足(此题使用 TRIGGER 触发了优惠券扣取失败的错误)

+-----------------------------------------------------------------------------------------------+--------+
| TEST CASE                                                                                     | RESULT |
+-----------------------------------------------------------------------------------------------+--------+
| Case 3: [Unfilled] enough stock; best coupon doesn't suffice; insufficient balance and credit | PASS   |
+-----------------------------------------------------------------------------------------------+--------+

用例 4:已交付,库存充足,使用最好的优惠券

+------------------------------------------------+--------+
| TEST CASE                                      | RESULT |
+------------------------------------------------+--------+
| Case 4: [Filled] enough stock; use best coupon | PASS   |
+------------------------------------------------+--------+

用例 5:已交付,库存充足,无优惠券,余额充足

+--------------------------------------------------------------+--------+
| TEST CASE                                                    | RESULT |
+--------------------------------------------------------------+--------+
| Case 5: [Filled] enough stock; no coupon; sufficient balance | PASS   |
+--------------------------------------------------------------+--------+

用例 6:已交付,库存充足,有优惠券但打折后仍然不足,余额不足,但可以用信用抵扣

+-----------------------------------------------------------------------------------------------------+--------+
| TEST CASE                                                                                           | RESULT |
+-----------------------------------------------------------------------------------------------------+--------+
| Case 6: [Filled] enough stock; best coupon doesn't suffice; insufficient balance; sufficient credit | PASS   |
+-----------------------------------------------------------------------------------------------------+--------+

About

SJTU Fall 2023 CS3322 Lab1

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors