[英]PostgreSQL No space left Error for a self-join query
我有以下查詢產生一起購買的產品矩陣意味着具有相同的ticket_id
。 table calc_base
有500萬行(43gb)。 此查詢在具有122 GB RAM,16 CPU,600 SSD的計算機上運行。 CREATE INDEX ON calc_base(TICKET_ID);
create table calc_tmp as
select
a.product_id x_product_id,
a.product_desc x_product_desc,
b.product_id y_product_id,
b.product_desc y_product_desc,
a.units x_units,
b.units y_units,
a.sales x_sales,
b.sales y_sales,
a.flag x_flag,
b.flag y_flag
from calc_base a
inner join calc_base b on a.ticket_id = b.ticket_id;
45分鍾后所有其他查詢正常運行此查詢引發此錯誤:
org.postgresql.util.PSQLException: ERROR: could not extend file "base/12407/18990.223": No space left on device
Hint: Check free disk space.
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:116)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:83)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:83)
at dbAnalysis.config.NamedParamStatement.executeQuery(NamedParamStatement.java:31)
at dbAnalysis.dao.DbAccess.profile(DbAccess.java:61)
at dbAnalysis.Benchmark.perform(Benchmark.java:63)
at dbAnalysis.controller.ConsoleApplication.main(ConsoleApplication.java:95)
它與臨時文件大小有關嗎? 我想知道為什么在PostgreSQL中會發生這種行為。 我感謝任何解決這個問題的建議。
你在ticket_id
顯然有很多重復。 要查看生成的行數,可以運行以下查詢:
select sum(cnt * cnt)
from (select cb.ticket_id, count(*) as cnt
from calc_base cb
group by cb.ticket_id
) cb;
實際上,我意識到上面會計算NULL
,而你的查詢會過濾掉它。 如果值可以為NULL
where cb.ticket_id is not null
添加到子查詢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.