如何在Rails中引入复合主键

One line of code can 5x your Rails application performance. What if you could make a small change to your database design that would unlock massively more efficient data access? At Shopify, we dusted off some old database principles and did exactly that with the primary Rails application.

一行代码可以将您的Rails应用程序性能提高5倍。如果您可以对数据库设计进行小的更改,从而实现更高效的数据访问?在Shopify,我们重新审视了一些旧的数据库原则,并在主要的Rails应用程序中做到了这一点。

Engineering at Shopify

Shopify的工程

We’re hiring

我们正在招聘

See open roles

查看空缺职位

Databases are a key scalability bottleneck for many web applications. But what if you could make a small change to your database design that would unlock massively more efficient data access? At Shopify, we dusted off some old database principles and did exactly that with the primary Rails application that powers online stores for over a million merchants. In this post, we’ll walk you through how we did it, and how you can use the same trick to optimize your own applications.

对于许多Web应用程序来说,数据库是一个关键的可扩展性瓶颈。但是,如果您可以对数据库设计进行一些小的更改,从而实现更高效的数据访问,那该多好呢?在Shopify,我们重新研究了一些旧的数据库原则,并在为超过一百万商家提供在线商店功能的主要Rails应用程序中实现了这一点。在本文中,我们将向您介绍我们是如何做到这一点的,以及您如何使用相同的技巧来优化自己的应用程序。

Background

背景

A basic principle of database design is that data that is accessed together should be stored together. In a relational database, we see this principle at work in the design of individual records (rows), which are composed of bits of information that are often accessed and stored at the same time. When a query needs to access or update multiple records, this query will be faster if those rows are “near” to each other. In MySQL, the sequential ordering of rows on disk is dictated by the table’s primary key.Active Record is the portion of the Rails application framework that abstracts and simplifies database access. This layer introduces database practices and conventions that greatly simplify application development. One such convention is that all tables have a simple automatically incrementing integer primary key, often called `id`. This means that, for a typical Rails application, most d...

开通本站会员,查看完整译文。

Home - Wiki
Copyright © 2011-2024 iteam. Current version is 2.131.0. UTC+08:00, 2024-09-18 07:48
浙ICP备14020137号-1 $Map of visitor$