3.3. National Computer Level 3 Database Examination - Operation, Maintenance and Optimization (Questions and Answers)

Topic one:

Suppose there is a sales document detail table in a database in SQL Server 2008. The table creation statement is: CREATE TABLE sales document detail table (sales document number varchar(10), product number varchar(8), whether it is valid varchar(4), unit price money, quantity int, total price money) After the system has been running for a period of time, there are nearly 10 million pieces of data in this table.  The following operations exist in this system: select * from sales document detail table where sales document number = '135671445' and product number = '021' and whether it is valid = 'yes'; During the system operation, it was found that the efficiency of this operation is relatively low. The engineer made the following suggestions: Since the three conditions of "sales document number", "commodity number" and "validity" are used in the query, indexes can be created on these three columns respectively to improve query efficiency.  Can the three indexes established in the system engineer's suggestion improve query efficiency?  Please briefly explain why.  As the system running time increases, the system running speed gradually slows down. It is analyzed that the disk IO cannot meet the frequent reading and writing requirements of the database system.  Engineers suggested adding an identical disk and adjusting the two disks to RAID1 mode.  Please analyze whether this operation can improve the disk IO problem from both reading and writing aspects.
answer:

  1. "Sales document number", "commodity number", and "whether it is valid" are all query conditions, so indexing on these three columns can improve query efficiency. Columns that are often used as conditions in queries should be indexed to improve query efficiency.
  2. From the perspective of reading, adding an identical disk and adjusting the two disks to RAID1 mode can improve the reading efficiency and increase the storage space of the disk. Adding RAID1 mode adds a mirror, which improves the reliability of the system. sex. However, adding RAID1 will turn the system into multiple hard disks and increase the I/O overhead of the system. When the amount of data is large, it cannot improve the reading speed of the system very well.
    From a writing perspective, the writing speed of a RAID1 disk array is usually slower because the data has to be written to two hard drives separately and compared. Now a READ1 disk array has been added, which is equivalent to four hard disks. When writing data, two backups may be made, and the writing speed is slower.
    Therefore, from the perspective of both reading and writing, adding a RAID1 disk array is not a good way to solve the problem, and this method is not very recommended.

Topic 2:

There is a sales document detail table in a SQL Server database. The table creation statement is:
CREATE TABLE sales document detail table (
sales document number varchar(20),
product number varchar(8),
unit price money,
quantity int
);
when the system runs After a period of time, there are nearly 10 million pieces of data in this table. The programmer executes the following SQL statement in the database:
SELECT product number, sum (unit price * quantity) FROM sales document detail table WHERE unit price > 150 GROUP BY product number
to increase this Regarding query execution efficiency, please provide a solution to improve query execution efficiency without changing the SQL statement or making hardware adjustments. (5 points)
During the operation, it was found that the CPU usage of the system database was very high, reaching nearly 95%, reaching 100% during the peak period, and the system memory usage reached 90%, but the system I/O was very light. Business personnel reported that the system operation speed was slow. In order to improve the running speed of the system, without modifying the application program, the two engineers proposed two different solutions:
Solution 1: Add 1 CPU to the server
Solution 2: Double the memory to the server
Considering cost factors, now Only one plan can be selected for implementation at this stage. Please indicate which option is more reasonable under the current circumstances and give reasons. (5 points)

answer:

  1. After running for a period of time, there are nearly 10 million pieces of data, indicating that the amount of data written is very large. In this case, the index cannot be used, because the amount of writing is large, so the maintenance cost of the index will be very huge, and not only cannot it be improved Efficiency will reduce performance, so it is not suitable for query optimization.
    Since the question does not allow changing SQL statements, you cannot use denormalization or use temporary tables to trade space for time. The questions also do not allow hardware adjustments or hardware upgrades.
    The most suitable solution for this question is horizontal segmentation of the data table. Since there are many product numbers, horizontal segmentation should be performed according to the unit price range.

  2. The title explains that the database CPU usage is very high, reaching 95%, and even reaches 100% during the peak period. This shows that this system is in urgent need of solution one.
    Although the memory usage reaches 90%, if you can only choose one solution to implement due to cost factors, give priority to option one.

Topic three:

Insert image description here

answer:

  1. Increasing the main frequency of the CPU can slightly alleviate the problem of slow course selection. Because the CPU frequency is high, a lot of data is processed per unit time, but it cannot solve the problem of slow server response. In the question, the CPU usage rate reaches 100% during course selection. Increasing the CPU frequency cannot solve the inherent problem.
  2. Increasing memory can improve the problem of slow course selection. Increasing memory can increase the data processed to a certain extent. In the question, the memory usage rate reaches 95%, indicating that the memory is not completely used up. Therefore, memory capacity is not the cause of slow server response. .
  3. SLC is characterized by high cost, small capacity, and fast speed, while MLC is characterized by large capacity, low cost, but slow speed. Therefore, replacing MLC cannot improve the reading speed and cannot solve the problem of slow course selection.
  4. Changing online courses cannot solve the problem of slow course selection, because the network bandwidth usage in Ontology is only 20%, indicating that network problems are not the main reason for slow course selection.
  5. This can fundamentally solve the problem of slow course selection. The original verification SQL statement takes 1-2 minutes to complete. When a large number of students choose courses, the CPU and memory are mainly used to process SQL statements, and a large amount of resources are consumed, causing the server response to slow down. In this question, the low efficiency of the SQL statement is the main reason for the slow response of the server, and the SQL statement should be optimized. Generally speaking, inefficient SQL rain gear is often the main reason for poor system efficiency.

Topic four:

Insert image description here
answer:

  1. Modification difficulty level: Table partitioning is applicable to all databases, while table partitioning can only be used for specific databases. Table partitioning belongs to the physical design of the database, and table partitioning belongs to the logical design of the database. From the perspective of implementation, Engineer A’s solution is easy to implement.
  2. Use engineer B’s optimization plan, that is, table partitioning for processing. Because the characteristics of the partition table are: if the data is large and the data is segmented, different operations are used for different segments of data. It is suitable to use partition table. In this question, additions, deletions, modifications, and queries are often performed on the current month's data in the table. However, for the previous data, there is almost no need for operations, or the operations are limited to queries. Then the table can be partitioned by month. Thereby improving query efficiency.

Topic five:

Insert image description here
answer:

  1. The cause of disconnections is network problems. Because of the ping command, it was found that the packet loss reached 10%. However, the utilization rates of CPU, memory, disk I/0, etc. have not reached 100%, indicating that there is still a certain margin.
  2. The most likely bottleneck of the database server is memory. Because the memory usage reaches 80% without any operation, the usage is high. Indicates that the memory capacity is insufficient to support the server's activities.
    For a database server, if the usage rate exceeds 90% when the business is idle, it means that the server lacks CPU resources; if the CPU usage rate is still very low during peak periods, it means that the server has sufficient CPU resources. Based on this, the CPU usage of a database can be judged. The highest CPU usage in this question is only 12.5%, which shows that the CPU cannot be the bottleneck of the database server. Disk I/O is very low, indicating that it cannot be the bottleneck of the server.

Topic six:

Assume that a social networking website uses the SQL Server 2008 database management system. After one year of operation, the user operation speed has obviously slowed down, and the database server load is very high. After analysis by technicians, it was found that the reason for the slow speed is that users frequently visit the website to check whether they have New news. An engineer suggested using database replication technology to distribute relevant data tables to a read-only database on another server regularly (for example, 1 minute) for user query. Please analyze the pros and cons of this solution one by one from the three aspects of data consistency, user experience, and scalability. Explain whether this solution is feasible and briefly give reasons.

answer:

  1. Advantages: This solution can satisfy consistency. Because database snapshot replication technology is used, related tables can be distributed to another server to meet consistency requirements. Data update can be done automatically or manually. The update time can be set when establishing the distribution database, and the setting time is less than 1 minute. In this way the user experience can be satisfied. The distribution of the database is only carried out at the software level. For already established publications and subscriptions, you can delete them by pressing the delete button on the skin, and then reset them, which is highly scalable.
  2. Disadvantages: Increased overhead of a server.

Topic 7:

Suppose a supermarket management system uses SCL Sarer 214 database management system. In order to ensure reliable operation of the database, the database administrator set up a full backup of the database every 7 hours a day, and a backup policy of retaining data for 2 months. Even after 10 years of unified operation.(ore and database data have reached the point where uwB has to run for 3 hours every night to perform a full backup of the database, which affects the normal operation of night statistics and other services. At the same time, the backup space is also Very nervous. Please explain the reason for this phenomenon and propose optimization methods. (10 points)

  1. The reason for this phenomenon is that the system adopts a full backup strategy. As the business develops, the amount of data that needs to be backed up gradually increases, and the backup time becomes longer and longer, occupying system resources and thus affecting other businesses. The solution is to use the combined strategy of full backup + differential backup + log backup to back up the database.
    The combination strategy of full backup + differential backup + log backup refers to adding some differential backups to the full backup. For example, a full backup is performed at 0:00 every day, and then a differential backup is performed at 0:00 every day, and then there is a gap between the two backups. Add some log backups. This makes backup and recovery faster. And when the system fails, very little data is lost

Topic 8:

Insert image description here

  1. This solution is not feasible.
  2. Triggers can cascade changes through related tables in the database, which is safer than writing code directly in the foreground and ensures consistency, but at the same time increases the consumption of disk space. In business, batch operations are required. When triggered multiple times, the efficiency of the trigger is low, because it is equivalent to executing a SQL statement each time, which causes higher CPU consumption. Therefore, the optimization effect cannot be achieved from the perspective of time and space cost.
  3. Adding "Total Payment Amount" to the data document table is not the correct optimization method. You should add "Total Payment Amount" to the data document details to improve query efficiency.

Question 9

Insert image description here

  1. Add index to item number
  2. This architecture is a database server fault-tolerant architecture with dual-machine hot backup. Regardless of hardware improvement factors, this architecture can improve system performance and reliability.
    The reason is that dual-machine hot backup technology is a highly fault-tolerant application solution that combines software and hardware. The solution consists of two server systems, an external shared disk matrix and corresponding dual-machine hot backup software.
    In this fault-tolerant scheme, data security and confidentiality are greatly protected. User data is stored in an external shared disk array. When a server fails, the backup machine takes the initiative to take over the work of the host machine to ensure uninterrupted network servers.

Topic ten

Insert image description here

  1. SELECT COUNT (*) FROM student table JOIN department table ON student table. department number = department table. department number WHERE department name LIKE '%电%' has better performance.
    Reason: The T-SQL code needs to scan the department table first, and then re-scan the student table based on each record obtained by scanning to get the result. Use the written SQL statement to achieve the same function. After linking the student table with the department, filter based on conditions. You only need to scan the linked table once.
  2. Creating a composite index will not significantly improve the query efficiency of the second statement, because the ID number of the composite index is ranked first, and will not significantly improve the query efficiency of finding names, but it will obviously improve the query efficiency of the first statement.

Topic 11

A certain Xuemei library management system saves data on teachers who can borrow books. This data comes from teacher records developed by another developer of the personnel system. Now it is necessary to automatically synchronize teacher data to the library management system. The total number of teacher records is about 10,000, and the number of data modifications is about 2 per day.
In order to achieve automatic data synchronization, the library management system has launched a new data synchronization program. After the synchronization program went online, the administrator of the database found that the amount of data stored every day increased significantly, especially the database logs. Remove the data from the trivial system and reinsert the data.
It is now necessary to optimize the synchronization program. An engineer proposed two plans:
① Add a new trigger in the relevant table of the personnel system, extract the new data to the incremental data table, and the synchronization program will add the data in the incremental data table every 10 minutes Synchronized to the library management system.
@Create a new temporary database in the library management system, and add a table with the same structure as the eight things system. The synchronization program will transfer the personnel activities to the library management corresponding table every 10 minutes. In the library management officer The evidence of Tongxina and Xingzhongqi uses the Sp statement to be the evidence that the knot is stronger than that of Kunshu. After adding it, please refer to the system data of
the system data.
Please compare the two solutions from four aspects: the impact on the personnel system, the impact on the library management system, the overall operating efficiency of the system, and the complexity of coordination among related developers, and give reasons.

  1. Using Option 1, if the amount of data is large, it will affect the operation of the personnel system, but it will have little impact on the library management system. The overall operating efficiency of the system is high, and the coordination complexity of related developers is also small. Using Option 2 will affect the operation of the personnel system and library management system, and will also increase the system overhead and the complexity of coordinating key personnel, which is lower than 1.
    Overall,
    the reason why Option 1 is better than Option 2 is that in Option 1, coordination by relevant personnel is only required when designing triggers. When the amount of data is large, it may affect the operation of the personnel system, while in Option 2, coordination by developers is only required. The complexity is lower than that of option 1. Overall, it will increase the overhead of the library management system. Because the newly created database will occupy system overhead and affect the overall operating efficiency of the system.

Topic 12

A school's network billing system uses SQL Server 2008 as the database management system. The system needs to save each login and logout time of each user. The structure of the table is as follows. CREATE TABLE login log table (
serial number int identity (1, 1).
Account number varchar (8).
Login time datetime, logout time datetime, this time the Internet fee is real);
after the system has been running for a period of time, there are nearly 5 failures. Tens of millions of pieces of data. At this time, it is slow for users to check their expiration status according to their login time. In order to improve the user experience, we have divided the two phases of a certain project into a comparison table of reconstruction and modification. Please analyze the rationality of the suggestions (if reasonable, please provide the latest zoning and city plan) and explain the reasons
.
After the problem in ① was solved and the system ran smoothly for 3 years, the administrator considered upgrading the hardware. After monitoring, the system resource usage is as follows:
-CPU usage generally does not exceed 50%
·Memory usage is 90%
-Disk IO usage peaks at 90%-95%, mainly for read operations. An engineer gave two upgrades Hardware configuration plan:
Configuration -: 2 processors, 6 cores, clocked at 2.4GHz; 64GB memory, 300GB 10K to SAS hard drives, 3 pieces, RAIDO. Configuration 2
: 2 processors, 6 cores, clocked at 1.9 GHz128GB memory; 800GB solid-state drive SAS read-intensive MLC, 2 blocks, RAID1. Based on the above data, please explain which configuration is more reasonable without considering cost factors, and give the reasons.

  1. Create a partition function on the right side of the login time column in the login log table in units of months, and divide the login log table into 12 partitions, with each partition corresponding to each month of the year. Because the operation is limited to queries, establishing a partition table can effectively improve query efficiency.
  2. Use option two. For CPU, memory, and disk hardware devices, if the usage rate exceeds 90% when idle, it indicates that the hardware resources are scarce. If the usage rate is less than 90% during peak periods, it means that the hardware resources are sufficient. In this question, the memory and disk usage are as high as 90%, while the CPU usage is not higher than 50%, indicating that the memory and hard disk resources are scarce and need to be adjusted, while the memory resources are sufficient and do not need to be adjusted. Therefore, when adjusting hardware, the memory capacity and disk access efficiency should be improved. Compared with RAID0, RAID1 improves the writing speed and enhances the reliability of the system, but the writing efficiency is not improved.

Question 13

In SQL Server 2008, there are teacher tables (teacher number, name, department number, professional title) and department tables (department number, department name, number of senior professional titles). Please write a post-trigger trigger that meets the following requirements (let the trigger name be tri_zc).
Whenever a teacher with a senior professional title ("Professor" or "Associate Professor") is inserted into the teacher table, or when the professional title of a non-senior professional title teacher is changed to a senior professional title, the number of senior professional titles in the corresponding department in the department table is modified. . (Assume that one operation only inserts or changes the professional title of one teacher)

Answer: [Reference answer]
CREATE TRIGGER tric_zc
ON Teacher table
AFTER INSERT,UPDATE
AS
BEGIN
DECLATE@zc varchar(10),@dept varchar(30)
SEL @ze = (select department number FROM inserted)
IF @zc = 'Professor ' or 'Associate Professor'
Update Department table
Sel Number of senior professional titles = Number of senior professional titles + 1
Where Department number = @dept
End
[Problem-solving idea]
The SQL statement to create a trigger is: CREATE TRIGGER, and its syntax format is:
CREATE TRIGGER trigger Name
ON {table name | view name}
{FOR | AFTER | INSTEAD OF} {[INSERT] [,] [DELETE] [,] [UPDATE]}

AS
[ { IF UPDATE(column)
[{AND | OR } UPDATE(column)…]
SQL 语句

Supongo que te gusta

Origin blog.csdn.net/weixin_44391817/article/details/132378829
Recomendado
Clasificación