MYSQL性能调优及架构设计-影响MYSQL性能的相关因素之实例分析_MySQL
bitsCN.com
需求概述
一个简单的讨论区系统,需要有用户,用户组,组讨论区这三部分基本功能
简要分析
1) 须要存放用户数据的表;
2) 须要存放分组信息和用户与组关系的表;
3) 须要存放讨论信息的表
解决方案
原始方案一:
分别用4个表来存放用户,用户组,用户与组关系,以及各组的讨论帖子的信息。
user用户表
Field
Type
Null
Key
Default
Extra
id
int(11)
NO
nick_name
varchar(32)
NO
NULL
password
char(64)
YES
NULL
varchar(32)
NO
NULL
status
varchar(16)
NO
NULL
sexuality
char(1)
NO
NULL
msn
varchar(32)
YES
NULL
sign
varchar(64)
YES
NULL
brithday
date
YES
NULL
hobby
varchar(64)
YES
NULL
location
varchar(64)
YES
NULL
description
varchar(1024)
YES
NULL
groups分组表
Field
Type
Null
Key
Default
Extra
id
int(11)
NO
gmt_create
datetime
NO
NULL
gmt_modified
datetime
NO
NULL
name
varchar(32)
NO
NULL
status
varchar(16)
NO
NULL
description
varchar(1024)
YES
NULL
user_group关系表
Field
Type
Null
Key
Default
Extra
user_id
int(11)
NO
MUL
NULL
group_id
int(11)
NO
MUL
NULL
user_type
int(11)
NO
NULL
gmt_create
datetime
NO
NULL
gmt_modified
datetime
NO
NULL
status
varchar(16)
NO
NULL
group_message讨论组帖子表
Field
Type
Null
Key
Default
Extra
id
int(11)
NO
NULL
gmt_create
datetime
NO
NULL
gmt_modified
datetime
NO
NULL
group_id
int(11)
NO
NULL
user_id
int(11)
NO
NULL
subject
varchar(128)
NO
NULL
content
text
YES
NULL
优化后方案二如下
user用户表分成user用户表与user_profile表
group_message讨论组表分成group_message讨论组与group_message_content
user用户表
Field
Type
Null
Key
Default
Extra
id
int(11)
NO
nick_name
varchar(32)
NO
NULL
password
char(64)
YES
NULL
varchar(32)
NO
NULL
status
varchar(16)
NO
NULL
user_profile用户属性表
Field
Type
Null
Key
Default
Extra
id
int(11)
NO
sexuality
char(1)
NO
NULL
msn
varchar(32)
YES
NULL
sign
varchar(64)
YES
NULL
brithday
date
YES
NULL
hobby
varchar(64)
YES
NULL
location
varchar(64)
YES
NULL
description
varchar(1024)
YES
NULL
group_message讨论组帖子表
Field
Type
Null
Key
Default
Extra
id
int(11)
NO
NULL
gmt_create
datetime
NO
NULL
gmt_modified
datetime
NO
NULL
group_id
int(11)
NO
NULL
user_id
int(11)
NO
NULL
subject
varchar(128)
NO
NULL
author
varchar(32)
NO
NULL
group_message_content帖子内容表
Field
Type
Null
Key
Default
Extra
group_msg_id
int(11)
NO
content
text
NO
NULL
分析考虑:
1. 从实际出发,一个讨论区系统,访问最多的页面应该是帖子标题列表页面。而帖子标题列表页面最主要的信息都来自于group_message表中,同时帖子标题后面的作者一般都是通过用户名(昵称)来展示。因此:
1) 按照第一种解决方案:
SELECT t.id, t.subject, user.id, u.nick_name
FROM
(
SELECT id, user_id, subject
FROM group_message
WHERE group_id = ?
ORDER BY gmt_modified DESC LIMIT 20
) t, user u
WHERE t.user_id = u.id
2) 按照第二种解决方案:
SELECT t.id, t.subject, t.user_id, t.author
FROM group_message t
HWERE group_id = ?
ORDER BY gmt_modified DESC LIMIT 20
两个查询一比较,打搅就能很明显地看出谁优谁劣了。
2. 由于第一方案中的group_message 表中还包含一个大字段’content’,该字段存放的信息要占整个表的绝大部分存储空间,但在1中表现的最频繁的Query完全不需要该字段所存放的信息,所以,造成了Query读取大量没有任何意义的数据。因此,需要把content字段单独分出来存放在group_message_content帖子内容表中。
作者”邪恶的小Y的博客“
bitsCN.com
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What happens when someone calls in airplane mode? Mobile phones have become one of the indispensable tools in people's lives. It is not only a communication tool, but also a collection of entertainment, learning, work and other functions. With the continuous upgrading and improvement of mobile phone functions, people are becoming more and more dependent on mobile phones. With the advent of airplane mode, people can use their phones more conveniently during flights. However, some people are worried about what impact other people's calls in airplane mode will have on the mobile phone or the user? This article will analyze and discuss from several aspects. first

When trying to open a disk image in VirtualBox, you may encounter an error indicating that the hard drive cannot be registered. This usually happens when the VM disk image file you are trying to open has the same UUID as another virtual disk image file. In this case, VirtualBox displays error code VBOX_E_OBJECT_NOT_FOUND(0x80bb0001). If you encounter this error, don’t worry, there are some solutions you can try. First, you can try using VirtualBox's command line tools to change the UUID of the disk image file, which will avoid conflicts. You can run the command `VBoxManageinternal

Java is a commonly used programming language used to develop various applications. However, just like other programming languages, Java has security vulnerabilities and risks. One of the common vulnerabilities is the file inclusion vulnerability (FileInclusionVulnerability). This article will explore the principle, impact and how to prevent this vulnerability. File inclusion vulnerabilities refer to the dynamic introduction or inclusion of other files in the program, but the introduced files are not fully verified and protected, thus

The impact of data scarcity on model training requires specific code examples. In the fields of machine learning and artificial intelligence, data is one of the core elements for training models. However, a problem we often face in reality is data scarcity. Data scarcity refers to the insufficient amount of training data or the lack of annotated data. In this case, it will have a certain impact on model training. The problem of data scarcity is mainly reflected in the following aspects: Overfitting: When the amount of training data is insufficient, the model is prone to overfitting. Overfitting refers to the model over-adapting to the training data.

On the Douyin platform, users can not only share their life moments, but also interact with other users. Sometimes the comment function may cause some unpleasant experiences, such as online violence, malicious comments, etc. So, how to turn off the comment function of TikTok? 1. How to turn off the comment function of Douyin? 1. Log in to Douyin APP and enter your personal homepage. 2. Click "I" in the lower right corner to enter the settings menu. 3. In the settings menu, find "Privacy Settings". 4. Click "Privacy Settings" to enter the privacy settings interface. 5. In the privacy settings interface, find "Comment Settings". 6. Click "Comment Settings" to enter the comment setting interface. 7. In the comment settings interface, find the "Close Comments" option. 8. Click the "Close Comments" option to confirm closing comments.

Bad sectors on a hard disk refer to a physical failure of the hard disk, that is, the storage unit on the hard disk cannot read or write data normally. The impact of bad sectors on the hard drive is very significant, and it may lead to data loss, system crash, and reduced hard drive performance. This article will introduce in detail the impact of hard drive bad sectors and related solutions. First, bad sectors on the hard drive may lead to data loss. When a sector in a hard disk has bad sectors, the data on that sector cannot be read, causing the file to become corrupted or inaccessible. This situation is especially serious if important files are stored in the sector where the bad sectors are located.

Some users may consider buying mining cards for the sake of cheapness. After all, these cards are top-notch graphics cards. However, some gamers are worried about the impact of mining cards on playing games. Let’s take a look at the detailed introduction below. What are the effects of using a mining card to play games: 1. The stability of playing games with a mining card cannot be guaranteed, because the life of the mining card is very short and it is likely to become useless after just playing. 2. The mining card is basically a castrated version of the original version. Due to long-term wear and tear, the performance in all aspects may be weak. 3. In this way, users may not be able to display all the effects of the game when playing the game. 4. Moreover, the electronic components of the graphics card will age in advance, not to mention that playing games also consumes the graphics card, so it is drained to a greater extent, so the impact on the game is great. 5. In general, use mining cards to play games

Some users find that the computer prompts that IPv6 does not have network access rights, but they can also surf the Internet normally. Therefore, some users do not know the impact of IPv6 without network access rights. Now I will introduce the specific situation to you. What is the impact of ipv6 without network access rights? Answer: There is no impact of ipv6 without network access rights. This situation shows that the switch or router is closed for the IPV6 protocol, but it has no impact on our daily use, and generally there is no need to turn it on. They are all enabled according to their own needs. Extended reading on IPV6: 1. IPV6 is the abbreviation of Internet Protocol version 6. It is the next generation IP protocol used to replace IPV4. 2. The number of IPv6 addresses is said to be enough to give sand
