技巧一、速度和完整性的折中 在多个文档中使用的数据可以采用内嵌(反范式话)的方式,也可以采用引用(范式化)的方式。这种策略并没有优劣之分,各自都有优缺点。关键是要选择适合自己的应用场景方案。 反范式化会产生不一致的数据。但要是范式化,应用则
技巧一、速度和完整性的折中
在多个文档中使用的数据可以采用内嵌(反范式话)的方式,也可以采用引用(范式化)的方式。这种策略并没有优劣之分,各自都有优缺点。关键是要选择适合自己的应用场景方案。 反范式化会产生不一致的数据。但要是范式化,应用则必须在每次确认时做额外一次查找。因为极高的性能和瞬间一致性不可兼得,所以必须要想清楚哪个才是应用最需要的。
考虑因素一般包括:
是否总要额外读取一次几乎不怎么改变的数据?
一致性很重要吗?
要不要快速读取?
技巧二、适应未来的数据要范式化
范式化可使数据可用性更加长久,未来可以在不同的应用中以不同的方式查询范式化的数据。这里的前提是有些数据将会一年不断地被各种应用得到。技巧三、尽量单个查询获得数据
mongodb的数据库设计应该从应用单元的查询出发。 应用单元,对于web应用或者移动应用可以将对后端的一次请求视作一个应用单元 对于桌面应用,一次用户交互可以算是一个应用单元 对于分析系统,一个图表的加载算作是一个应用单元技巧四、嵌入关联数据
当在嵌入和引用文档之间犹豫不决时候,不防想想查询的目的是为了获得字段本身还是为了进一步获得更加广泛的信息。如果前者建议采用嵌入关联数据。技巧五、嵌入时间点数据
比如某人更新了个人信息,那么就不需要更改其以往的订单内容技巧六、不要嵌入不断增加的数据
mongodb存储数据的机制决定了对数据的不断追加数据是很低效的。在正常使用中数据和对象的大小应该相对固定。技巧七、预填充数据
如果已经知道未来要用到哪些字段,第一次插入是就带着这些字段会比用到时再创建效率更高。 比如每天都要使用新的集合,最好提前创建。技巧八、尽可能预先分配空间
只要知道文档开始比较小,后来会变得确定的大小,就可以使用这种优化方法。 一开始插入文档的时候就用和最终数据大小一样的垃圾数据填充。即添加一个garbage字段(其中包含一个字符串,串大小与文档最终大小相同)技巧九、用数组存放要匿名访问的内嵌数据
一个常见的问题就是内嵌信息到底是欧也妮个数据还是用文档来存。如果确切知道查询内容就用子文档存。如果有时不太清楚查询的具体内容,则要数组。 当知道一些条目的查询条件时候通常该使用数组。技巧十:文档要自给自足
mongodb是一个无脑的大型数据存储。mongodb几乎不做任何数据处理,仅仅存储数据。要尽量遵守这点,避免让mongodb做些能在客户端完成的计算。即便是写小任务,像求平均值或求和,也要放在客户端去做。
如果要找的信息必须经过计算,且无法直接从文档中获得,有两种定义:
付出高昂的性能代价;优化文档结构,使得这些信息能够从文档中直接获得。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools