Mysql水平分表_MySQL
bitsCN.com
Mysql在数据量大的情况下,会遇到水平分表的情况。
1. 根据业务属性拆表
这种分表方式的算法大致是取模,hash,md5等。
用业务属性拆表,业务关系复杂的情况下,如果要根据其他条件查询,其他的条件都必须和这个属性关联起来,查询条件必须带有这个属性。
例子:
用户profile表根据用户ID取模进行水平拆分。
社区里有群组,群组里有应用,应用有各种类型。可以用群组ID,应用ID拆表。
问题:
根据某个条件查询时无法获取拆表的属性
1) 条件中含有分表的信息
比如用户在某网站下了订单,我们根据用户ID对订单进行了分表,这样用户可以方便地查询他所关联的订单。但用户投诉时,客服需要根据订单号查询订单,订单号中可以含有分表的信息,比如订单拆分成100张表,订单号中可以有两位用来表明该订单处于哪张表中
2) 用key-value store存储对应关联
原理是用key value store做索引表
3) 数据冗余
需要关联的表可以进行数据冗余。避免了查询。
例子:
购买礼品。购买虚拟礼品时,我们根据了购买者的ID进行了拆表,同时订单号中也含有了分表信息。但是用户还可能根据被赠送方进行查询,这时我们可以在购买成功后为被赠送方冗余生成一条记录。
4) 缓存,NOSQL
和数据冗余类似。例子中提到的群组应用的拆表例子,我们已经按照群组ID和应用类型进行了分表。但是当我要查询最近所有类型的应用时,就遇到困难了。我们需要把该群组的所有应用类型都查询一遍,而且还要再进行排序,分页等等。其实,可以用缓存的方式存储最近几百条应用。
2. 根据时间拆表
当表的关系比较复杂时,无法根据某个维度进行分表。但是有明显的时效性。
例子:
想必大家都用微薄,某人发的微薄,会被推送到千家万户。所以某条微薄是无法根据用户ID进行分表查询。而微薄是有很强的时效性的。一年前的默认的动态信息是不会再关心的。我们把微薄按时间分表,三个月一张表。而行级缓存(memcached)只存储了一个月。用户微薄收件箱(微薄ID列表)一般都是限长的。当缓存服务器重启或不命中时,需要查询Mysql,mysql按时间分表,缓存不命中的情况下,大部分情况下都是查近三个月的微薄。所以近1年的微薄我们可以存储在物理资源比较好的数据库服务器上。
3. 根据自增长ID拆表
这种分割法不是取模分,而是每张表存指定量的数据。如果数据量到了,就存放到新表中。这样可以完全控制每张表的数据量。关系非常简单并且有时效性的情况下可以用。
4. 数据迁移的方式
当一些很久之前的数据,很少再查询。比如员工工资表,我们可以只存今年的工资情况。而历史数据我们可以迁移到一张salary_old表中,保证数据不会丢失。但也可以用来查询。
分库的原理也类似。
by 第零空间 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

MySQL vs. TiDB: Which is better for your business? With the rapid development of the Internet and big data, data storage and management have become an important part of enterprise business. When choosing a suitable database solution, many enterprises come across the two choices of MySQL and TiDB. This article will compare the features and advantages of MySQL and TiDB to help you determine which one is more suitable for your business. MySQL is an open source relational database management system that was born as early as 1995

Preface: ChatGPT is really very popular recently, and AI services related to ChatGPT are also being researched in full swing. Today we take a look at the application of ChatGPT in coding. Recently we found an IntelliJ IDEA plug-in called "AI Coding Assistant", which integrates ChatGPT technology. Let's see how smart it is and whether it will really work in the future. It is possible that it will replace the work of our programmers. Plugin Installation In order to start using the plugin, you must have an OpenAI token. If you don't know where to find it, you can find it at https://platform.openai.c

Integrated communication service refers to the integration of communication technology and information technology. It can provide voice, fax, video call, called one-number service and other services to China Mobile mobile phone users, IMS fixed-line users and traditional fixed-line users, and can integrate the three services. Class users are unified into a network to provide converged V network services, enabling users to achieve cross-network, cross-region, and cross-terminal converged communications.

Good software is not discovered by program analysis and error detection, but is built by the right people. Graphs have become an increasingly important computing object. The graph structure is an abstraction of group relationships and can describe rich objects and relationships. The core of graph computing is how to model data into a graph structure and how to transform the solution of the problem into a computing problem on the graph structure. When the problem involves correlation analysis, graph computing can often make the solution to the problem naturally expressed as a A series of operations and calculations on graph structures. For example, the PageRank algorithm based on the graph structure of web page links is used to obtain the weight of the web page, which is used as a reference for search engine ranking. The user behavior data of the graph structure is used to obtain accurate group preference analysis and personalized product recommendation results. 1.What is plotting?

ChatGPT has indeed begun to replace humans! The US Fortune magazine website recently reported that the job advice platform Resumebuilder.com conducted a survey among 1,000 business leaders who use or plan to use ChatGPT. The results show that nearly 50% of companies in the United States have begun to use ChatGPT. About half said ChatGPT had replaced employees at their company. Sure enough, what was supposed to come came! Half of U.S. companies are using ChatGPT. According to a survey of these business leaders, ChatGPT covers almost all levels of the company's business. There are many reasons why companies use ChatGPT, 66% for writing code, 58% for writing copywriting, and 57% for customer use.

1. Problems and Challenges As you can see from the figure, since 2017, vivo’s machine scale and number of services have grown significantly. In terms of machine scale, it has increased by about five times from 2017 to 2022, and the number of services has also basically increased by more than ten times. As the scale grows, challenges and complexity will definitely increase. Typical challenges in vivo are mainly divided into change challenges and failure challenges. 1. Change challenges There are still more or less manual change scenarios in the change; our single release time is relatively long; there are many scenarios of large-scale business migration; Google SRE has such a concept: 70% failure is caused by changes. Corresponding to vivo, this situation does exist. The change affects online stability.

Title: Does ByteDance use Golang in its business? Exploration and case analysis In the current Internet industry, Golang, as an efficient, concise, and excellent concurrency programming language, has been favored by more and more companies. Among them, ByteDance, whose main business is content sharing and short videos, does it also use Golang in its technology stack? This article will explore ByteDance’s use of Golang in its business and analyze it through specific code examples. Golang in ByteDance

This article is reprinted with the authorization of AI New Media Qubit (public account ID: QbitAI). Please contact the source for reprinting. Technology companies affected by the collapse of Silicon Valley Bank can breathe a little easier. On the one hand, wealthy people in the technology industry have stepped in to help: Sam Altman, CEO of OpenAI, the company behind ChatGPT, was exposed as having provided financial assistance totaling more than US$1 million to companies that were unable to pay salaries due to Silicon Valley Bank. . And he didn’t ask for any IOUs or documents. He just said, “You will pay me back when you have money.” On the other hand, U.S. regulators are determined to hold back. According to a joint statement issued by the U.S. Treasury Department, the Federal Reserve (Fed), and the Federal Deposit Insurance Corporation (FDIC), Silicon Valley Bank
