Re: PoC/WIP: Extended statistics on expressions

Tomas Vondra <tomas.vondra@enterprisedb.com>

From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>, pgsql-hackers@postgresql.org
Date: 2021-03-24T08:54:22Z
Lists: pgsql-hackers
Hi Justin,

Unfortunately the query is incomplete, so I can't quite determine what
went wrong. Can you extract the full query causing the crash, either
from the server log or from a core file?

thanks

On 3/24/21 9:14 AM, Justin Pryzby wrote:
> I got this crash running sqlsmith:
> 
> #1  0x00007f907574b801 in __GI_abort () at abort.c:79
> #2  0x00005646b95a35f8 in ExceptionalCondition (conditionName=conditionName@entry=0x5646b97411db "bms_num_members(varnos) == 1", errorType=errorType@entry=0x5646b95fa00b "FailedAssertion", 
>     fileName=fileName@entry=0x5646b9739dbe "selfuncs.c", lineNumber=lineNumber@entry=3332) at assert.c:69
> #3  0x00005646b955c9a1 in add_unique_group_expr (vars=0x5646bbd9e200, expr=0x5646b9eb0c30, exprinfos=0x5646bbd9e100, root=0x5646ba9a0cb0) at selfuncs.c:3332
> #4  add_unique_group_expr (root=0x5646ba9a0cb0, exprinfos=0x5646bbd9e100, expr=0x5646b9eb0c30, vars=0x5646bbd9e200) at selfuncs.c:3307
> #5  0x00005646b955d560 in estimate_num_groups () at selfuncs.c:3558
> #6  0x00005646b93ad004 in create_distinct_paths (input_rel=<optimized out>, root=0x5646ba9a0cb0) at planner.c:4808
> #7  grouping_planner () at planner.c:2238
> #8  0x00005646b93ae0ef in subquery_planner (glob=glob@entry=0x5646ba9a0b98, parse=parse@entry=0x5646ba905d80, parent_root=parent_root@entry=0x0, hasRecursion=hasRecursion@entry=false, tuple_fraction=tuple_fraction@entry=0)
>     at planner.c:1024
> #9  0x00005646b93af543 in standard_planner (parse=0x5646ba905d80, query_string=<optimized out>, cursorOptions=256, boundParams=<optimized out>) at planner.c:404
> #10 0x00005646b94873ac in pg_plan_query (querytree=0x5646ba905d80, 
>     query_string=0x5646b9cd87e0 "select distinct \n  \n    pg_catalog.variance(\n      cast(pg_catalog.pg_stat_get_bgwriter_timed_checkpoints() as int8)) over (partition by subq_0.c2 order by subq_0.c0) as c0, \n  subq_0.c2 as c1, \n  sub"..., cursorOptions=256, boundParams=0x0) at postgres.c:821
> #11 0x00005646b94874a1 in pg_plan_queries (querytrees=0x5646baaba250, 
>     query_string=query_string@entry=0x5646b9cd87e0 "select distinct \n  \n    pg_catalog.variance(\n      cast(pg_catalog.pg_stat_get_bgwriter_timed_checkpoints() as int8)) over (partition by subq_0.c2 order by subq_0.c0) as c0, \n  subq_0.c2 as c1, \n  sub"..., cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0) at postgres.c:912
> #12 0x00005646b9487888 in exec_simple_query () at postgres.c:1104
> 
> 2021-03-24 03:06:12.489 CDT postmaster[11653] LOG:  server process (PID 11696) was terminated by signal 6: Aborted
> 2021-03-24 03:06:12.489 CDT postmaster[11653] DETAIL:  Failed process was running: select distinct 
>           
>             pg_catalog.variance(
>               cast(pg_catalog.pg_stat_get_bgwriter_timed_checkpoints() as int8)) over (partition by subq_0.c2 order by subq_0.c0) as c0, 
>           subq_0.c2 as c1, 
>           subq_0.c0 as c2, 
>           subq_0.c2 as c3, 
>           subq_0.c1 as c4, 
>           subq_0.c1 as c5, 
>           subq_0.c0 as c6
>         from 
>           (select  
>                 ref_1.foreign_server_catalog as c0, 
>                 ref_1.authorization_identifier as c1, 
>                 sample_2.tgname as c2, 
>                 ref_1.foreign_server_catalog as c3
>               from 
>                 pg_catalog.pg_stat_database_conflicts as ref_0
>                         left join information_schema._pg_user_mappings as ref_1
>                         on (ref_0.datname < ref_0.datname)
>                       inner join pg_catalog.pg_amproc as sample_0 tablesample system (5) 
>                       on (cast(null as uuid) < cast(null as uuid))
>                     left join pg_catalog.pg_aggregate as sample_1 tablesample system (2.9) 
>                     on (sample_0.amprocnum = sample_1.aggnumdirectargs )
>                   inner join pg_catalog.pg_trigger as sample_2 tablesampl
> 

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



Commits

  1. Disallow extended statistics on system columns

  2. Identify simple column references in extended statistics

  3. Don't print extra parens around expressions in extended stats

  4. Change position of field "transformed" in struct CreateStatsStmt.

  5. Add transformed flag to nodes/*funcs.c for CREATE STATISTICS

  6. Stabilize stats_ext test with other collations

  7. Extended statistics on expressions

  8. Reduce duration of stats_ext regression tests

  9. Allow composite types in catalog bootstrap

  10. Convert Typ from array to list in bootstrap

  11. Disallow CREATE STATISTICS on system catalogs