[原创]状态值在数据库中的检索
对于关系型数据库而言,针对表的检索,一般来说,建立合适的索引就可以达到很好的检索效果。(这里不包含表设计的合理与否)比如像状态列这样可选择性非常低的值
对于关系型数据库而言,针对表的检索,一般来说,建立合适的索引就可以达到很好的检索效果。(这里不包含表设计的合理与否)
比如像状态列这样可选择性非常低的值,该如何检索? 其实这个已经不是关系型数据库擅长的方面了。 但是如果出于历史或者许多不可抗拒的原因,
我们还得在关系表中进行优化,该咋办? 一般来说,就是建立静态表。 但是静态表也是多重多样,该如何选择? 我下面列举几个简单的例子,当然了,
由于个人的脑子尺度不够大,有可能有些遗漏。
原始表。
20 完条记录, 大概36MB大小。
t_girl>create table rank_status (id integer not null, i_status varchar(3) not null);第一种呢,就是建立LIST 表,这种表,可以当做静态表,也可以当做原始表来做相关的更新。
只有2条记录,大概720KB大小。
t_girl>create table rank_status_extend (i_status varchar(3) not null, ids text);我们可以对两张表都做对应的更新操作。
插入一条记录。
t_girl> insert into rank_status values (222222,'yes'); Time: 4.397 ms t_girl>update rank_status_extend set ids = ids ||','||'222222' where i_status = 'yes'; Time: 43.725 ms删除一条记录。
t_girl>delete from rank_status where i_status = 'yes' and id = 1; Time: 47.339 ms t_girl>update rank_status_extend set ids = replace(ids,',1,',',') where i_status = 'yes'; Time: 45.046 ms更新一条记录。
t_girl>update rank_status set id = 1000 where i_status = 'yes' and id = 20; Time: 65.834 ms t_girl>update rank_status_extend set ids = replace(ids,',20,',',1000,') where i_status = 'yes'; Time: 85.974 ms我们看到,在对表的写操作中,第二张表会比第一张慢一点。
其实我们最主要的是关心读操作。其实在读上面还是很有优势的。
接下来第二种呢,就是分别建立两张表, 但是这两张表呢,少了存放状态值的字段,所以在尺寸上小了很多。
t_girl>create table rank_status_yes (id int not null); 3552 kB t_girl>create table rank_status_no(id int not null); 3584 kB当然这张表的检索肯定比原始表来的快,这里,我就不演示了。
第三种呢,就是建立一张物化视图,
t_girl>create materialized view mv_rank_status_yes as select * from rank_status where i_status = 'yes';这种其实和第二种表很类似。只不过不同的是第二种表的维护需要人工来做,而这个视图系统可以维护。
本文出自 “上帝,咱们不见不散!” 博客,请务必保留此出处
,
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

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 and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

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.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Abstract of the first paragraph of the article: When choosing software to develop Yi framework applications, multiple factors need to be considered. While native mobile application development tools such as XCode and Android Studio can provide strong control and flexibility, cross-platform frameworks such as React Native and Flutter are becoming increasingly popular with the benefits of being able to deploy to multiple platforms at once. For developers new to mobile development, low-code or no-code platforms such as AppSheet and Glide can quickly and easily build applications. Additionally, cloud service providers such as AWS Amplify and Firebase provide comprehensive tools

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...
