日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

oracle analyze分区表,PostgreSQL Analyze分区表:主表与子表的统计信息问题

發布時間:2024/10/5 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle analyze分区表,PostgreSQL Analyze分区表:主表与子表的统计信息问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近在PostgreSQL的Mail List中參與討論了一個問題: ANALYZE'ing table hierarchies。

網友認為在Analyze分區表的時候,只能看到主表的analyze日期更新到最新,但是子表的日期沒有變化,他認為analyze應該是在分析主表的時候會將與之相關的子表一起更新。

為此測試了一下,發現無論主表還是子表,需要單獨的對其進行analyze才可以更新其最新的統計信息。

以下是實驗部分:

music=> create table music(id int,name text,style text);

CREATE TABLE

music=> create table rock (check(style = 'rock')) inherits(music);

CREATE TABLE

music=> create table pop (check(style = 'pop')) inherits(music);

CREATE TABLE

music=> create table classic (check(style = 'classic')) inherits(music);

CREATE TABLE

music=> ?create table jazz (check(style = 'jazz')) inherits(music);

CREATE TABLE

music=> \dS+ music

Table "eric.music"

Column | ?Type ? | Modifiers | Storage ?| Stats target | Description

--------+---------+-----------+----------+--------------+-------------

id ? ? | integer | ? ? ? ? ? | plain ? ?| ? ? ? ? ? ? ?|

name ? | text ? ?| ? ? ? ? ? | extended | ? ? ? ? ? ? ?|

style ?| text ? ?| ? ? ? ? ? | extended | ? ? ? ? ? ? ?|

Child tables: classic,

jazz,

pop,

rock

music=> create index music_pop_id on pop (id);

CREATE INDEX

music=> ?create index music_rock_id on rock (id);

CREATE INDEX

music=> create index music_jazz_id on jazz (id);

CREATE INDEX

music=> create index music_classic_id on classic (id);

CREATE INDEX

music=> ?CREATE OR REPLACE FUNCTION music_insert_trigger()

music-> ?RETURNS TRIGGER AS

music-> ?$$

music$> ?BEGIN

music$> ? ? ? IF (NEW.style = 'rock') THEN

music$> ? ? ? ? ? INSERT INTO rock VALUES (NEW.*);

music$> ? ? ? ELSEIF (NEW.style = 'pop') THEN

music$> ? ? ? ? ? INSERT INTO pop VALUES (NEW.*);

music$> ? ? ? ELSEIF (NEW.style = 'pop') THEN

music$> ? ? ? ? ? INSERT INTO pop VALUES (NEW.*);

music$> ? ? ? ELSEIF (NEW.style = 'jazz') THEN

music$> ? ? ? ? ? INSERT INTO jazz VALUES (NEW.*);

music$> ? ? ? ELSEIF (NEW.style = 'classic') THEN

music$> ? ? ? ? ? INSERT INTO classic VALUES (NEW.*);

music$> ? ? ? END IF;

music$> ? ? ? RETURN NULL;

music$> ?END;

music$> ?$$

music-> ?LANGUAGE plpgsql ;

CREATE FUNCTION

music=> CREATE TRIGGER insert_music_trigger

music-> BEFORE INSERT ON ?music

music-> FOR EACH row EXECUTE PROCEDURE music_insert_trigger() ;

CREATE TRIGGER

music=> insert into music values(2,'Have a Nice Day','pop');

INSERT 0 0

music=> insert into music values(1,'21 Gun','rock');

INSERT 0 0

music=> select * from music;

id | ? ? ?name ? ? ? | style

----+-----------------+-------

1 | 21 Gun ? ? ? ? ?| rock

2 | Have a Nice Day | pop

(2 rows)

music=> select * from pop;

id | ? ? ?name ? ? ? | style

----+-----------------+-------

2 | Have a Nice Day | pop

(1 row)

music=> select * from rock;

id | ?name ?| style

----+--------+-------

1 | 21 Gun | rock

(1 row)

music=> analyze verbose music ;

INFO: ?analyzing "eric.music"

INFO: ?"music": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows

INFO: ?analyzing "eric.music" inheritance tree

INFO: ?"rock": scanned 1 of 1 pages, containing 1 live rows and 0 dead rows; 1 rows in sample, 1 estimated total rows

INFO: ?"pop": scanned 1 of 1 pages, containing 1 live rows and 0 dead rows; 1 rows in sample, 1 estimated total rows

ANALYZE

music=> select relname, last_analyze from pg_stat_user_tables where relname = 'music';

relname | ? ? ? ? last_analyze

---------+-------------------------------

music ? | 2016-02-18 22:29:56.528758-08

(1 row)

music=> select relname, last_analyze from pg_stat_user_tables where relname = 'pop';

relname | last_analyze

---------+--------------

pop ? ? |

(1 row)

music=> select relname, last_analyze from pg_stat_user_tables where relname = 'rock';

relname | last_analyze

---------+--------------

rock ? ?|

(1 row)

music=> analyze verbose pop;

INFO: ?analyzing "eric.pop"

INFO: ?"pop": scanned 1 of 1 pages, containing 1 live rows and 0 dead rows; 1 rows in sample, 1 estimated total rows

ANALYZE

music=> select relname, last_analyze from pg_stat_user_tables where relname = 'rock';

relname | last_analyze

---------+--------------

rock ? ?|

(1 row)

music=> select relname, last_analyze from pg_stat_user_tables where relname = 'pop';

relname | ? ? ? ? last_analyze

---------+-------------------------------

pop ? ? | 2016-02-18 22:31:55.666556-08

(1 row)

music=> analyze verbose rock;

INFO: ?analyzing "eric.rock"

INFO: ?"rock": scanned 1 of 1 pages, containing 1 live rows and 0 dead rows; 1 rows in sample, 1 estimated total rows

ANALYZE

music=> select relname, last_analyze from pg_stat_user_tables where relname = 'rock';

relname | ? ? ? ? last_analyze

---------+-------------------------------

rock ? ?| 2016-02-18 22:34:16.526558-08

(1 row)

總結

以上是生活随笔為你收集整理的oracle analyze分区表,PostgreSQL Analyze分区表:主表与子表的统计信息问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。