PostgreSQL中列的statistics属性
PostgreSQL中列的statistics属性 这个属性大概来说是用来控制分析时对列的分析的详细程度,会影响到执行计划的选择,具体的描述可以看文档。pgsql默认所有列的statistics都是100,这是个相当保守的数字,即对列中不同值的分析是很粗糙的。在列值分布不均匀的
PostgreSQL中列的statistics属性
这个属性大概来说是用来控制分析时对列的分析的详细程度,会影响到执行计划的选择,具体的描述可以看文档。pgsql默认所有列的statistics都是100,这是个相当保守的数字,即对列中不同值的分析是很粗糙的。在列值分布不均匀的情况下,经常会看到执行计划用很粗略的平均值估算而选择了非最优的路径。 www.2cto.com
通过调高这个参数,很多执行计划不正确的问题可以得到解决。特别是一些经常用到的查询列,提高默认参数很有必要。我感觉,提高到1000很有必要。按照官方文档,提高这个参数唯一的坏处是analyze时间会长一点。从实际情况来看,从100提高到1000基本感觉不到analyze时间有多少差别。
怎样才能知道某一列的statistics需要提高呢?最方便的就是用explain analyze了。如果发现执行计划里某个步骤执行结果的估算值(row)和实际获得值(actual)相差很悬殊,那么就很有必要提高这个参数了。怎么提高呢?
alter table [table name] alter column [column name] set statistics=1000;
提高完了记得重新analyze一下表。
还有一个需要注意的地方,有的地方是索引里的列值估算不准确(具体看执行计划),这时候需要调整索引里的列的statistics,方法和调整表一样,把索引当成表:
alter table [index name] alter column [column name] set statistics=1000;

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



TogetintliteralattributeinsteadofSyntaxError,useaspaceorparenthesis.TheintliteralisapartifNumericLiteralsinPython.NumericLiteralsalsoincludesthefollowingfourdifferentnumericaltypes−int(signedintegers)−Theyareoftencalledjustintegersorints,arepositiveo

The Gson@SerializedName annotation can be serialized to JSON and have the provided name value as its field name. This annotation can override any FieldNamingPolicy, including the default field naming policy that may have been set on the Gson instance. Different naming strategies can be set using the GsonBuilder class. Syntax@Retention(value=RUNTIME)@Target(value={FIELD,METHOD})public@interfaceSerializedNameExample importcom.google.gson.annotations.*;

Python's dir() function: View an object's properties and methods, specific code example required Summary: Python is a powerful and flexible programming language, and its built-in functions and tools provide developers with many convenient features. One of the very useful functions is the dir() function, which allows us to view the properties and methods of an object. This article will introduce the usage of the dir() function and demonstrate its functions and uses through specific code examples. Text: Python’s dir() function is a built-in function.

MySQL and PostgreSQL: Performance Comparison and Optimization Tips When developing web applications, the database is an indispensable component. When choosing a database management system, MySQL and PostgreSQL are two common choices. They are both open source relational database management systems (RDBMS), but there are some differences in performance and optimization. This article will compare the performance of MySQL and PostgreSQL and provide some optimization tips. Performance comparison comparing two database management

MySQL and PostgreSQL: Best Practices in Web Development Introduction: In the modern world of web development, databases are an essential component. When choosing a database, common choices are MySQL and PostgreSQL. This article will cover best practices for using MySQL and PostgreSQL in web development and provide some code examples. 1. Applicable scenarios MySQL is suitable for most web applications, especially those that require high performance, scalability and ease of use.

MySQL and PostgreSQL: Data Security and Backup Strategies Introduction: In modern society, data has become an indispensable part of business and personal life. For database management systems, data security and backup strategies are crucial, both to protect data from loss or damage and to ensure the reliability and integrity of recovered data. This article will focus on the data security and backup strategies of two mainstream relational database systems, MySQL and PostgreSQL. 1. Data security: (1) User rights

Learn the database functions in the Go language and implement the addition, deletion, modification, and query operations of PostgreSQL data. In modern software development, the database is an indispensable part. As a powerful programming language, Go language provides a wealth of database operation functions and toolkits, which can easily implement addition, deletion, modification and query operations of the database. This article will introduce how to learn database functions in Go language and use PostgreSQL database for actual operations. Step 1: Install the database driver in Go language for each database

Bottom attribute syntax and code examples in CSS In CSS, the bottom attribute is used to specify the distance between an element and the bottom of the container. It controls the position of an element relative to the bottom of its parent element. The syntax of the bottom attribute is as follows: element{bottom:value;} where element represents the element to which the style is to be applied, and value represents the bottom value to be set. value can be a specific length value, such as pixels
