我尝试为 postgresql 8.3 创建一个 plpgsql 触发器,它在通过 id 列插入之前自动对表进行分区
如果目标表不存在,它将被创建,然后插入到那里
所以我用这样的新表名创建了插入语句
exec_insert := 'INSERT INTO '||TG_TABLE_SCHEMA||'.'||TG_RELNAME||'_'||destinationid||' VALUES('||NEW.*||')';
EXECUTE exec_insert;
Run Code Online (Sandbox Code Playgroud)
导致错误:
ERROR: NEW used in query that is not in a rule
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
谢谢
我将时间序列模拟结果存储在 PostgreSQL 中。数据库模式是这样的。
table SimulationInfo (
simulation_id integer primary key,
simulation_property1,
simulation_property2,
....
)
table SimulationResult ( // The size of one row would be around 100 bytes
simulation_id integer,
res_date Date,
res_value1,
res_value2,
...
res_value9,
primary key (simulation_id, res_date)
Run Code Online (Sandbox Code Playgroud)
)
我通常根据simulation_id和res_date查询数据。
我根据simulation_id的范围值将SimulationResult表分为200个子表。一个完全填满的子表有10~1500万行。目前约有70个子表已满,数据库大小超过100GB。总共 200 个子表很快就会被填满,当这种情况发生时,我需要添加更多的子表。
但我读了这个答案,它说超过几十个分区是没有意义的。所以我的问题如下。
超过几十个分区没有意义吗?为什么?我检查了我的200个子表的执行计划,它只扫描相关的子表。所以我猜分区越多,每个子表越小一定更好。
如果分区数量应该受到限制,比如 50 个,那么一张表中有数十亿行没有问题吗?考虑到像我这样的模式,一张表可以有多大而不会有大问题?
我有一个按 to_days(created_at) 范围进行分区的数据库。
分区是每月的(p1 - p50),最后有一个 pmax 包罗万象的内容。在下面的示例中,我预计只有分区 p45 会被命中。
当我进行解释分区时,从created_at>“2013-01-01 00:00:00”和NOW()的单元中选择*
我在分区列下列出了 p1,p45
5.1 和 5.5 中都会发生这种情况
为什么优化器包括用于不等式检查的第一个分区?
当我在oracle表上创建索引并且只指定列名和表名(基本上是默认索引)时,它是创建全局索引还是本地分区索引(即根据表分区对索引进行分区)?
我试图更好地理解 SQL 中的分析函数。
我的理解是否正确,即窗口函数将应用于“分区依据”中出现的每个唯一的字段组合?
如果我要将结果集划分为多个字段,这些字段的出现顺序重要吗?
更具体地说,以下两个查询的结果在任何情况下都会有所不同吗?
Select customer_code,
state,
weekOfDate,
SUM(Sales) over(partition by customer_code,state,weekOfDate)
From Sales
Select customer_code,
state,
weekOfDate,
SUM(Sales) over(partition by weekOfDate,state,customer_code)
From Sales
Run Code Online (Sandbox Code Playgroud) 在haskell中,如何生成集合的平衡分区?
假设我有一组{1,3,4,6,9},该组将是一个平衡的分区s1{9,3}和s2{6,4,1},看到s1-s2是1.
我创建了一个分区类型为day的表,并已从命令行工具将time_partitioning_expiration设置为1209600秒(14天)bq。我通过bq show在表上运行来验证设置是否正确,我可以看到
"timePartitioning": {
"expirationMs": "1209600000",
"type": "DAY"
},
"type": "TABLE"
Run Code Online (Sandbox Code Playgroud)
但是,分区中似乎有一些我希望删除的数据。
SELECT
count(*) as c,
_partitiontime as pDate
FROM [poc.reporting]
group by pDate
;
1 373800 2016-07-17 00:00:00 UTC
2 640800 2016-07-18 00:00:00 UTC
3 373800 2016-07-16 00:00:00 UTC
Run Code Online (Sandbox Code Playgroud)
我的理解是,设置time_partition_expiration将在内部删除/删除分区吗?如果是这样,为什么我没有删除分区?
我正在尝试按照此处的建议创建一个用于存储时间序列数据的垂直分区表。
到目前为止,我的架构如下所示:
CREATE TABLE events
(
topic text,
t timestamp,
value integer,
primary key(topic, t)
);
CREATE TABLE events_2014
(
primary key (topic, t),
check (t between '2014-01-01' and '2015-01-01')
) INHERITS (events);
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试创建一个INSTEAD OF INSERT触发器,以便可以在events表中插入事件,并且该行将最终出现在正确的子表中。但是文档说INSTEAD OF INSERT触发器只能在视图上创建,不能在表(或子表)上创建:
CREATE OR REPLACE FUNCTION insert_events () RETURNS TRIGGER AS $insert_events$ BEGIN
IF new.t between '2014-01-01' and '2015-01-01' THEN
INSERT INTO events_2014 SELECT new.*;
...
END IF
RETURN NULL;
END;
$insert_events$ LANGUAGE PLPGSQL;
CREATE TRIGGER …Run Code Online (Sandbox Code Playgroud) 使用AWS :: Glue :: Table,您可以像此处那样建立Athena表。雅典娜支持在S3中基于文件夹结构对数据进行分区。我想从我的Glue模板对Athena表进行分区。
从AWS Glue Table TableInput看来,我可以使用它PartitionKeys来对数据进行分区,但是当我尝试使用以下模板时,Athena失败并且无法获取任何数据。
Resources:
...
MyGlueTable:
Type: AWS::Glue::Table
Properties:
DatabaseName: !Ref MyGlueDatabase
CatalogId: !Ref AWS::AccountId
TableInput:
Name: my-glue-table
Parameters: { "classification" : "json" }
PartitionKeys:
- {Name: dt, Type: string}
StorageDescriptor:
Location: "s3://elasticmapreduce/samples/hive-ads/tables/impressions/"
InputFormat: "org.apache.hadoop.mapred.TextInputFormat"
OutputFormat: "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
SerdeInfo:
Parameters: { "separatorChar" : "," }
SerializationLibrary: "org.apache.hive.hcatalog.data.JsonSerDe"
StoredAsSubDirectories: false
Columns:
- {Name: requestBeginTime, Type: string}
- {Name: adId, Type: string}
- …Run Code Online (Sandbox Code Playgroud) 我有一个当前按年份拆分的分区方案设置。我正在尝试为明年创建一个新分区:
ALTER PARTITION SCHEME psYearlyPartition_Log
NEXT USED Year7FileGroup;
ALTER PARTITION FUNCTION pfYearlyPartition_Log()
SPLIT RANGE('20190101');
Run Code Online (Sandbox Code Playgroud)
然而,这运行了很多小时并且没有完成。有谁知道为什么会发生这种情况,因为似乎还没有任何 2019 年的数据?
最后一个分区是从 2016-01-01 到今天。
我在这篇文章的底部运行了查询,结果如下:
CREATE PARTITION FUNCTION [pfYearlyPartition](datetime) AS RANGE LEFT FOR VALUES('2012-01-01T00:00:00','2013-01-01T00:00:00','2014-01-01T00:00:00','2015-01-01T00:00:00','2016-01-01T00:00:00');
CREATE PARTITION SCHEME [psYearlyPartition_Table1] AS PARTTITION [pfYearlyPartition] TO ([YEAR1FileGroup],[YEAR2FileGroup],[YEAR3FileGroup],[YEAR4FileGroup],[YEAR5FileGroup],[YEAR6FileGroup],[YEAR11FileGroup]);
CREATE PARTITION SCHEME [psYearlyPartition_Table2] AS PARTTITION [pfYearlyPartition] TO ([YEAR1FileGroup],[YEAR2FileGroup],[YEAR3FileGroup],[YEAR4FileGroup],[YEAR5FileGroup],[YEAR6FileGroup],[YEAR11FileGroup]);
CREATE PARTITION SCHEME [psYearlyPartition_Table3] AS PARTTITION [pfYearlyPartition] TO ([YEAR1FileGroup],[YEAR2FileGroup],[YEAR3FileGroup],[YEAR4FileGroup],[YEAR5FileGroup],[YEAR6FileGroup],[YEAR11FileGroup]);
CREATE PARTITION SCHEME [psYearlyPartition_Table4] AS PARTTITION [pfYearlyPartition] TO ([YEAR1FileGroup],[YEAR2FileGroup],[YEAR3FileGroup],[YEAR4FileGroup],[YEAR5FileGroup],[YEAR6FileGroup],[YEAR11FileGroup]);
CREATE PARTITION SCHEME [psYearlyPartition_Table5] AS PARTTITION [pfYearlyPartition] TO ([YEAR1FileGroup],[YEAR2FileGroup],[YEAR3FileGroup],[YEAR4FileGroup],[YEAR5FileGroup],[YEAR6FileGroup],[YEAR11FileGroup]);
CREATE PARTITION SCHEME [psYearlyPartition_Table6] AS …Run Code Online (Sandbox Code Playgroud) partitioning ×10
postgresql ×3
sql ×3
algorithm ×1
analytical ×1
aws-glue ×1
haskell ×1
indexing ×1
inheritance ×1
mysql ×1
oracle ×1
plpgsql ×1
sql-server ×1
triggers ×1
windowing ×1