BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop

From: tcook(at)blackducksoftware(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Cc: tcook(at)blackducksoftware(dot)com
Subject: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop
Date: 2017-11-27 18:57:00
Message-ID: 20171127185700.1470.20362@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14932
Logged by: Todd Cook
Email address: tcook(at)blackducksoftware(dot)com
PostgreSQL version: 10.1
Operating system: CentOS Linux release 7.4.1708 (Core)
Description:

It hangs on a table with 167834 rows, though it works fine with only 167833
rows. When it hangs, CTRL-C does not interrupt it, and the backend has to
be killed to stop it.

Some sample stack traces:

#0 0x00007f66f1ee9860 in __memset_sse2 () from /lib64/libc.so.6
#1 0x000000000083e085 in memset (__len=51539607552, __ch=0,
__dest=0x7f4cdf35c048) at /usr/include/bits/string3.h:84
#2 MemoryContextAllocExtended (context=<optimized out>, size=51539607552,
flags=flags(at)entry=5) at mcxt.c:843
#3 0x00000000005ec804 in tuplehash_allocate (type=0x163ecc8,
size=<optimized out>) at ../../../src/include/lib/simplehash.h:305
#4 tuplehash_grow (tb=0x163ecc8, newsize=<optimized out>) at
../../../src/include/lib/simplehash.h:379
#5 0x00000000005ece35 in tuplehash_insert (tb=0x163ecc8, key=key(at)entry=0x0,
found=found(at)entry=0x7ffdaff3eb77 "") at
../../../src/include/lib/simplehash.h:504
#6 0x00000000005ed3ea in LookupTupleHashEntry (hashtable=0x163ec38,
slot=slot(at)entry=0x163e220, isnew=isnew(at)entry=0x7ffdaff3ebd7 "") at
execGrouping.c:387
#7 0x00000000005fae62 in lookup_hash_entry (aggstate=0x163ce88) at
nodeAgg.c:2075
#8 lookup_hash_entries (aggstate=aggstate(at)entry=0x163ce88) at
nodeAgg.c:2106
#9 0x00000000005fc5da in agg_fill_hash_table (aggstate=0x163ce88) at
nodeAgg.c:2536
#10 ExecAgg (pstate=0x163ce88) at nodeAgg.c:2140
#11 0x00000000005eec32 in ExecProcNode (node=0x163ce88) at
../../../src/include/executor/executor.h:250
#12 ExecutePlan (execute_once=<optimized out>, dest=0x163bbf8,
direction=<optimized out>, numberTuples=0, sendTuples=1 '\001',
operation=CMD_SELECT, use_parallel_mode=<optimized out>,
planstate=0x163ce88, estate=0x163cc28) at execMain.c:1722
#13 standard_ExecutorRun (queryDesc=0x163c818, direction=<optimized out>,
count=0, execute_once=<optimized out>) at execMain.c:363
#14 0x0000000000718e3b in PortalRunSelect (portal=portal(at)entry=0x158a568,
forward=forward(at)entry=1 '\001', count=0, count(at)entry=9223372036854775807,
dest=dest(at)entry=0x163bbf8) at pquery.c:932
#15 0x000000000071a1ef in PortalRun (portal=<optimized out>,
count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized
out>, dest=0x163bbf8, altdest=0x163bbf8, completionTag=0x7ffdaff3eed0 "") at
pquery.c:773
#16 0x0000000000716163 in exec_simple_query (query_string=<optimized out>)
at postgres.c:1099
#17 0x000000000071745c in PostgresMain (argc=<optimized out>,
argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at
postgres.c:4088
#18 0x000000000047ad1c in BackendRun (port=0x1592ab0) at postmaster.c:4357
#19 BackendStartup (port=0x1592ab0) at postmaster.c:4029
#20 ServerLoop () at postmaster.c:1753
#21 0x00000000006aea2f in PostmasterMain (argc=argc(at)entry=3,
argv=argv(at)entry=0x156bed0) at postmaster.c:1361
#22 0x000000000047bb4f in main (argc=3, argv=0x156bed0) at main.c:228
Continuing.

Program received signal SIGINT, Interrupt.
0x00000000005ec8ac in tuplehash_grow (tb=0x163ecc8, newsize=<optimized out>)
at ../../../src/include/lib/simplehash.h:443
443 newentry = &newdata[curelem];
#0 0x00000000005ec8ac in tuplehash_grow (tb=0x163ecc8, newsize=<optimized
out>) at ../../../src/include/lib/simplehash.h:443
#1 0x00000000005ece35 in tuplehash_insert (tb=0x163ecc8, key=key(at)entry=0x0,
found=found(at)entry=0x7ffdaff3eb77 "") at
../../../src/include/lib/simplehash.h:504
#2 0x00000000005ed3ea in LookupTupleHashEntry (hashtable=0x163ec38,
slot=slot(at)entry=0x163e220, isnew=isnew(at)entry=0x7ffdaff3ebd7 "") at
execGrouping.c:387
#3 0x00000000005fae62 in lookup_hash_entry (aggstate=0x163ce88) at
nodeAgg.c:2075
#4 lookup_hash_entries (aggstate=aggstate(at)entry=0x163ce88) at
nodeAgg.c:2106
#5 0x00000000005fc5da in agg_fill_hash_table (aggstate=0x163ce88) at
nodeAgg.c:2536
#6 ExecAgg (pstate=0x163ce88) at nodeAgg.c:2140
#7 0x00000000005eec32 in ExecProcNode (node=0x163ce88) at
../../../src/include/executor/executor.h:250
#8 ExecutePlan (execute_once=<optimized out>, dest=0x163bbf8,
direction=<optimized out>, numberTuples=0, sendTuples=1 '\001',
operation=CMD_SELECT, use_parallel_mode=<optimized out>,
planstate=0x163ce88, estate=0x163cc28) at execMain.c:1722
#9 standard_ExecutorRun (queryDesc=0x163c818, direction=<optimized out>,
count=0, execute_once=<optimized out>) at execMain.c:363
#10 0x0000000000718e3b in PortalRunSelect (portal=portal(at)entry=0x158a568,
forward=forward(at)entry=1 '\001', count=0, count(at)entry=9223372036854775807,
dest=dest(at)entry=0x163bbf8) at pquery.c:932
#11 0x000000000071a1ef in PortalRun (portal=<optimized out>,
count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized
out>, dest=0x163bbf8, altdest=0x163bbf8, completionTag=0x7ffdaff3eed0 "") at
pquery.c:773
#12 0x0000000000716163 in exec_simple_query (query_string=<optimized out>)
at postgres.c:1099
#13 0x000000000071745c in PostgresMain (argc=<optimized out>,
argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at
postgres.c:4088
#14 0x000000000047ad1c in BackendRun (port=0x1592ab0) at postmaster.c:4357
#15 BackendStartup (port=0x1592ab0) at postmaster.c:4029
#16 ServerLoop () at postmaster.c:1753
#17 0x00000000006aea2f in PostmasterMain (argc=argc(at)entry=3,
argv=argv(at)entry=0x156bed0) at postmaster.c:1361
#18 0x000000000047bb4f in main (argc=3, argv=0x156bed0) at main.c:228
Continuing.

Program received signal SIGINT, Interrupt.
0x00000000005ec8ac in tuplehash_grow (tb=0x163ecc8, newsize=<optimized out>)
at ../../../src/include/lib/simplehash.h:443
443 newentry = &newdata[curelem];
#0 0x00000000005ec8ac in tuplehash_grow (tb=0x163ecc8, newsize=<optimized
out>) at ../../../src/include/lib/simplehash.h:443
#1 0x00000000005ece35 in tuplehash_insert (tb=0x163ecc8, key=key(at)entry=0x0,
found=found(at)entry=0x7ffdaff3eb77 "") at
../../../src/include/lib/simplehash.h:504
#2 0x00000000005ed3ea in LookupTupleHashEntry (hashtable=0x163ec38,
slot=slot(at)entry=0x163e220, isnew=isnew(at)entry=0x7ffdaff3ebd7 "") at
execGrouping.c:387
#3 0x00000000005fae62 in lookup_hash_entry (aggstate=0x163ce88) at
nodeAgg.c:2075
#4 lookup_hash_entries (aggstate=aggstate(at)entry=0x163ce88) at
nodeAgg.c:2106
#5 0x00000000005fc5da in agg_fill_hash_table (aggstate=0x163ce88) at
nodeAgg.c:2536
#6 ExecAgg (pstate=0x163ce88) at nodeAgg.c:2140
#7 0x00000000005eec32 in ExecProcNode (node=0x163ce88) at
../../../src/include/executor/executor.h:250
#8 ExecutePlan (execute_once=<optimized out>, dest=0x163bbf8,
direction=<optimized out>, numberTuples=0, sendTuples=1 '\001',
operation=CMD_SELECT, use_parallel_mode=<optimized out>,
planstate=0x163ce88, estate=0x163cc28) at execMain.c:1722
#9 standard_ExecutorRun (queryDesc=0x163c818, direction=<optimized out>,
count=0, execute_once=<optimized out>) at execMain.c:363
#10 0x0000000000718e3b in PortalRunSelect (portal=portal(at)entry=0x158a568,
forward=forward(at)entry=1 '\001', count=0, count(at)entry=9223372036854775807,
dest=dest(at)entry=0x163bbf8) at pquery.c:932
#11 0x000000000071a1ef in PortalRun (portal=<optimized out>,
count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized
out>, dest=0x163bbf8, altdest=0x163bbf8, completionTag=0x7ffdaff3eed0 "") at
pquery.c:773
#12 0x0000000000716163 in exec_simple_query (query_string=<optimized out>)
at postgres.c:1099
#13 0x000000000071745c in PostgresMain (argc=<optimized out>,
argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at
postgres.c:4088
#14 0x000000000047ad1c in BackendRun (port=0x1592ab0) at postmaster.c:4357
#15 BackendStartup (port=0x1592ab0) at postmaster.c:4029
#16 ServerLoop () at postmaster.c:1753
#17 0x00000000006aea2f in PostmasterMain (argc=argc(at)entry=3,
argv=argv(at)entry=0x156bed0) at postmaster.c:1361
#18 0x000000000047bb4f in main (argc=3, argv=0x156bed0) at main.c:228
Continuing.

Program received signal SIGINT, Interrupt.
tuplehash_grow (tb=0x163ecc8, newsize=<optimized out>) at
../../../src/include/lib/simplehash.h:450
450 curelem = SH_NEXT(tb, curelem, startelem);
#0 tuplehash_grow (tb=0x163ecc8, newsize=<optimized out>) at
../../../src/include/lib/simplehash.h:450
#1 0x00000000005ece35 in tuplehash_insert (tb=0x163ecc8, key=key(at)entry=0x0,
found=found(at)entry=0x7ffdaff3eb77 "") at
../../../src/include/lib/simplehash.h:504
#2 0x00000000005ed3ea in LookupTupleHashEntry (hashtable=0x163ec38,
slot=slot(at)entry=0x163e220, isnew=isnew(at)entry=0x7ffdaff3ebd7 "") at
execGrouping.c:387
#3 0x00000000005fae62 in lookup_hash_entry (aggstate=0x163ce88) at
nodeAgg.c:2075
#4 lookup_hash_entries (aggstate=aggstate(at)entry=0x163ce88) at
nodeAgg.c:2106
#5 0x00000000005fc5da in agg_fill_hash_table (aggstate=0x163ce88) at
nodeAgg.c:2536
#6 ExecAgg (pstate=0x163ce88) at nodeAgg.c:2140
#7 0x00000000005eec32 in ExecProcNode (node=0x163ce88) at
../../../src/include/executor/executor.h:250
#8 ExecutePlan (execute_once=<optimized out>, dest=0x163bbf8,
direction=<optimized out>, numberTuples=0, sendTuples=1 '\001',
operation=CMD_SELECT, use_parallel_mode=<optimized out>,
planstate=0x163ce88, estate=0x163cc28) at execMain.c:1722
#9 standard_ExecutorRun (queryDesc=0x163c818, direction=<optimized out>,
count=0, execute_once=<optimized out>) at execMain.c:363
#10 0x0000000000718e3b in PortalRunSelect (portal=portal(at)entry=0x158a568,
forward=forward(at)entry=1 '\001', count=0, count(at)entry=9223372036854775807,
dest=dest(at)entry=0x163bbf8) at pquery.c:932
#11 0x000000000071a1ef in PortalRun (portal=<optimized out>,
count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized
out>, dest=0x163bbf8, altdest=0x163bbf8, completionTag=0x7ffdaff3eed0 "") at
pquery.c:773
#12 0x0000000000716163 in exec_simple_query (query_string=<optimized out>)
at postgres.c:1099
#13 0x000000000071745c in PostgresMain (argc=<optimized out>,
argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at
postgres.c:4088
#14 0x000000000047ad1c in BackendRun (port=0x1592ab0) at postmaster.c:4357
#15 BackendStartup (port=0x1592ab0) at postmaster.c:4029
#16 ServerLoop () at postmaster.c:1753
#17 0x00000000006aea2f in PostmasterMain (argc=argc(at)entry=3,
argv=argv(at)entry=0x156bed0) at postmaster.c:1361
#18 0x000000000047bb4f in main (argc=3, argv=0x156bed0) at main.c:228
Continuing.

Program received signal SIGINT, Interrupt.
0x00000000005ec8ac in tuplehash_grow (tb=0x163ecc8, newsize=<optimized out>)
at ../../../src/include/lib/simplehash.h:443
443 newentry = &newdata[curelem];
#0 0x00000000005ec8ac in tuplehash_grow (tb=0x163ecc8, newsize=<optimized
out>) at ../../../src/include/lib/simplehash.h:443
#1 0x00000000005ece35 in tuplehash_insert (tb=0x163ecc8, key=key(at)entry=0x0,
found=found(at)entry=0x7ffdaff3eb77 "") at
../../../src/include/lib/simplehash.h:504
#2 0x00000000005ed3ea in LookupTupleHashEntry (hashtable=0x163ec38,
slot=slot(at)entry=0x163e220, isnew=isnew(at)entry=0x7ffdaff3ebd7 "") at
execGrouping.c:387
#3 0x00000000005fae62 in lookup_hash_entry (aggstate=0x163ce88) at
nodeAgg.c:2075
#4 lookup_hash_entries (aggstate=aggstate(at)entry=0x163ce88) at
nodeAgg.c:2106
#5 0x00000000005fc5da in agg_fill_hash_table (aggstate=0x163ce88) at
nodeAgg.c:2536
#6 ExecAgg (pstate=0x163ce88) at nodeAgg.c:2140
#7 0x00000000005eec32 in ExecProcNode (node=0x163ce88) at
../../../src/include/executor/executor.h:250
#8 ExecutePlan (execute_once=<optimized out>, dest=0x163bbf8,
direction=<optimized out>, numberTuples=0, sendTuples=1 '\001',
operation=CMD_SELECT, use_parallel_mode=<optimized out>,
planstate=0x163ce88, estate=0x163cc28) at execMain.c:1722
#9 standard_ExecutorRun (queryDesc=0x163c818, direction=<optimized out>,
count=0, execute_once=<optimized out>) at execMain.c:363
#10 0x0000000000718e3b in PortalRunSelect (portal=portal(at)entry=0x158a568,
forward=forward(at)entry=1 '\001', count=0, count(at)entry=9223372036854775807,
dest=dest(at)entry=0x163bbf8) at pquery.c:932
#11 0x000000000071a1ef in PortalRun (portal=<optimized out>,
count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized
out>, dest=0x163bbf8, altdest=0x163bbf8, completionTag=0x7ffdaff3eed0 "") at
pquery.c:773
#12 0x0000000000716163 in exec_simple_query (query_string=<optimized out>)
at postgres.c:1099
#13 0x000000000071745c in PostgresMain (argc=<optimized out>,
argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at
postgres.c:4088
#14 0x000000000047ad1c in BackendRun (port=0x1592ab0) at postmaster.c:4357
#15 BackendStartup (port=0x1592ab0) at postmaster.c:4029
#16 ServerLoop () at postmaster.c:1753
#17 0x00000000006aea2f in PostmasterMain (argc=argc(at)entry=3,
argv=argv(at)entry=0x156bed0) at postmaster.c:1361
#18 0x000000000047bb4f in main (argc=3, argv=0x156bed0) at main.c:228
Continuing.

Program received signal SIGINT, Interrupt.
0x00000000005ec8b4 in tuplehash_grow (tb=0x163ecc8, newsize=<optimized out>)
at ../../../src/include/lib/simplehash.h:445
445 if (newentry->status == SH_STATUS_EMPTY)
#0 0x00000000005ec8b4 in tuplehash_grow (tb=0x163ecc8, newsize=<optimized
out>) at ../../../src/include/lib/simplehash.h:445
#1 0x00000000005ece35 in tuplehash_insert (tb=0x163ecc8, key=key(at)entry=0x0,
found=found(at)entry=0x7ffdaff3eb77 "") at
../../../src/include/lib/simplehash.h:504
#2 0x00000000005ed3ea in LookupTupleHashEntry (hashtable=0x163ec38,
slot=slot(at)entry=0x163e220, isnew=isnew(at)entry=0x7ffdaff3ebd7 "") at
execGrouping.c:387
#3 0x00000000005fae62 in lookup_hash_entry (aggstate=0x163ce88) at
nodeAgg.c:2075
#4 lookup_hash_entries (aggstate=aggstate(at)entry=0x163ce88) at
nodeAgg.c:2106
#5 0x00000000005fc5da in agg_fill_hash_table (aggstate=0x163ce88) at
nodeAgg.c:2536
#6 ExecAgg (pstate=0x163ce88) at nodeAgg.c:2140
#7 0x00000000005eec32 in ExecProcNode (node=0x163ce88) at
../../../src/include/executor/executor.h:250
#8 ExecutePlan (execute_once=<optimized out>, dest=0x163bbf8,
direction=<optimized out>, numberTuples=0, sendTuples=1 '\001',
operation=CMD_SELECT, use_parallel_mode=<optimized out>,
planstate=0x163ce88, estate=0x163cc28) at execMain.c:1722
#9 standard_ExecutorRun (queryDesc=0x163c818, direction=<optimized out>,
count=0, execute_once=<optimized out>) at execMain.c:363
#10 0x0000000000718e3b in PortalRunSelect (portal=portal(at)entry=0x158a568,
forward=forward(at)entry=1 '\001', count=0, count(at)entry=9223372036854775807,
dest=dest(at)entry=0x163bbf8) at pquery.c:932
#11 0x000000000071a1ef in PortalRun (portal=<optimized out>,
count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized
out>, dest=0x163bbf8, altdest=0x163bbf8, completionTag=0x7ffdaff3eed0 "") at
pquery.c:773
#12 0x0000000000716163 in exec_simple_query (query_string=<optimized out>)
at postgres.c:1099
#13 0x000000000071745c in PostgresMain (argc=<optimized out>,
argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at
postgres.c:4088
#14 0x000000000047ad1c in BackendRun (port=0x1592ab0) at postmaster.c:4357
#15 BackendStartup (port=0x1592ab0) at postmaster.c:4029
#16 ServerLoop () at postmaster.c:1753
#17 0x00000000006aea2f in PostmasterMain (argc=argc(at)entry=3,
argv=argv(at)entry=0x156bed0) at postmaster.c:1361
#18 0x000000000047bb4f in main (argc=3, argv=0x156bed0) at main.c:228

select name, setting, unit, source, pending_restart from pg_settings where
source <> 'default' and context <> 'internal' order by lower(name) ;
name | setting | unit | source
| pending_restart
------------------------------+--------------------+------+----------------------+-----------------
application_name | psql | | client
| f
autovacuum_work_mem | 131072 | kB | configuration
file | f
checkpoint_completion_target | 0.8 | | configuration
file | f
checkpoint_timeout | 1800 | s | configuration
file | f
client_encoding | SQL_ASCII | | client
| f
cluster_name | PG 10 | | configuration
file | f
DateStyle | ISO, MDY | | configuration
file | f
default_text_search_config | pg_catalog.english | | configuration
file | f
dynamic_shared_memory_type | posix | | configuration
file | f
effective_cache_size | 8388608 | 8kB | configuration
file | f
lc_messages | C | | configuration
file | f
lc_monetary | C | | configuration
file | f
lc_numeric | C | | configuration
file | f
lc_time | C | | configuration
file | f
listen_addresses | * | | configuration
file | f
log_destination | stderr | | configuration
file | f
log_line_prefix | %m [%p] | | configuration
file | f
log_lock_waits | on | | configuration
file | f
log_min_duration_statement | 20000 | ms | configuration
file | f
log_rotation_age | 1440 | min | configuration
file | f
log_rotation_size | 0 | kB | configuration
file | f
log_temp_files | 1024 | kB | configuration
file | f
log_timezone | US/Eastern | | configuration
file | f
log_truncate_on_rotation | off | | configuration
file | f
logging_collector | on | | configuration
file | f
maintenance_work_mem | 1048576 | kB | configuration
file | f
max_connections | 100 | | configuration
file | f
max_stack_depth | 2048 | kB | environment
variable | f
max_wal_senders | 0 | | configuration
file | f
max_wal_size | 4096 | MB | configuration
file | f
port | 54310 | | configuration
file | f
shared_buffers | 1048576 | 8kB | configuration
file | f
synchronous_commit | off | | configuration
file | f
TimeZone | US/Eastern | | configuration
file | f
transaction_deferrable | off | | override
| f
transaction_isolation | read committed | | override
| f
transaction_read_only | off | | override
| f
wal_buffers | 2048 | 8kB | override
| f
wal_level | minimal | | configuration
file | f
work_mem | 65536 | kB | configuration
file | f

select version();
version

---------------------------------------------------------------------------------------------------------
PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5
20150623 (Red Hat 4.8.5-16), 64-bit

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tomas Vondra 2017-11-27 19:17:25 Re: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop
Previous Message Jan Przemysław Wójcik 2017-11-27 15:28:37 Re: Lack of information on materialized views in information_schema.table_privileges.