pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Anton A. Melnikov <a.melnikov@postgrespro.ru>
To: John Naylor <johncnaylorls@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jeff Davis <pgsql@j-davis.com>
Cc: Ants Aasma <ants.aasma@cybertec.at>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Junwang Zhao <zhjwpku@gmail.com>
Cc: jian he <jian.universality@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Gurjeet Singh <gurjeet@singh.im>
Cc: pgsql-hackers@postgresql.org
Subject: Re: Change GUC hashtable to use simplehash?
Date: Wed, 12 Feb 2025 23:42:32 +0300
Message-ID: <f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru> (raw)
In-Reply-To: <CANWCAZai=YQNV_VY6tt=pL2RquU2NNr2WQbuj3G8hYeJBeGyyA@mail.gmail.com>
References: <c95e1821b6a69ec0c40eb0252e037b68a62cdae3.camel@j-davis.com>
	<CANWCAZbg_XeSeY0a_PqWmWqeRATvzTzUNYRLeT+bzs+YQdC92g@mail.gmail.com>
	<CANWCAZbwvp7oUEkbw-xP4L0_S_WNKq-J-ucP4RCNDPJnrakUPw@mail.gmail.com>
	<458350a908d9607f7fc2a15407f4405cc454c970.camel@j-davis.com>
	<CANWCAZYxrJJ4EDw=o5vu_gAs7dS_PK6ry0rqkVu9opGpAJjoQQ@mail.gmail.com>
	<2b0df3af97fac73a40aba16a58837e2cee594b1f.camel@j-davis.com>
	<CANWCAZYLvWOm-1XLT8wGoXGgNBEV_NPMWJY4gM6cXa7LHVDjtw@mail.gmail.com>
	<a3a959f6-14b8-4819-ac04-eaf2aa2e868d@postgrespro.ru>
	<CANWCAZZ0ptKxEyO504OjZOr3Co=WaSEQG5eUU-TFmqD4twhe_w@mail.gmail.com>
	<0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru>
	<1520769.1736991361@sss.pgh.pa.us>
	<16198d33-a4e2-46db-b6c3-494367f5816d@postgrespro.ru>
	<CANWCAZbg_pN72nwaeq5pyBOV__Cbs2=HoUPh8NJW3LuF48JkQw@mail.gmail.com>
	<CANWCAZY6rFYeFGGoW_eCVpubQ-QNtkbuumWQts-9FU8Qtc65cQ@mail.gmail.com>
	<4c739718-27d6-44fe-9113-56a251c13275@postgrespro.ru>
	<CANWCAZai=YQNV_VY6tt=pL2RquU2NNr2WQbuj3G8hYeJBeGyyA@mail.gmail.com>

Hi!

On 29.01.2025 10:02, John Naylor wrote:
> This is done -- thanks for the report, and for testing.

It's good that this is done! But i still see the problem.

At ecb8226a in master with the same configure as in [1]
(with asserts) valgrind gives:
==00:00:00:23.937 285792== Conditional jump or move depends on uninitialised value(s)
==00:00:00:23.937 285792==    at 0x3084A3: fasthash_accum (hashfn_unstable.h:142)
==00:00:00:23.937 285792==    by 0x3084A3: fasthash_accum_cstring_aligned (hashfn_unstable.h:299)
==00:00:00:23.937 285792==    by 0x3084A3: fasthash_accum_cstring (hashfn_unstable.h:323)
==00:00:00:23.937 285792==    by 0x3084A3: spcachekey_hash (namespace.c:268)
==00:00:00:23.937 285792==    by 0x308A3C: nsphash_lookup (simplehash.h:836)
==00:00:00:23.937 285792==    by 0x308A3C: spcache_insert (namespace.c:394)
==00:00:00:23.937 285792==    by 0x3095D9: cachedNamespacePath (namespace.c:4251)
==00:00:00:23.937 285792==    by 0x3096C2: recomputeNamespacePath (namespace.c:4309)
==00:00:00:23.937 285792==    by 0x3097B3: RelnameGetRelid (namespace.c:890)
==00:00:00:23.937 285792==    by 0x30AF72: RangeVarGetRelidExtended (namespace.c:539)
==00:00:00:23.937 285792==    by 0x2F0738: objectNamesToOids (aclchk.c:701)
==00:00:00:23.937 285792==    by 0x2F5EFF: ExecuteGrantStmt (aclchk.c:425)
==00:00:00:23.937 285792==    by 0x65E2E7: ProcessUtilitySlow (utility.c:1812)
==00:00:00:23.937 285792==    by 0x65CCB2: standard_ProcessUtility (utility.c:969)
==00:00:00:23.937 285792==    by 0x65CF84: ProcessUtility (utility.c:523)
==00:00:00:23.937 285792==    by 0x65A426: PortalRunUtility (pquery.c:1152)

Please see backtrace at bt-with-asserts-Og.txt attached.
   
Without asserts it falls in similar way:
==00:00:00:23.391 271086== Conditional jump or move depends on uninitialised value(s)
==00:00:00:23.391 271086==    at 0x2BE8FE: fasthash_accum (hashfn_unstable.h:180)
==00:00:00:23.391 271086==    by 0x2BE8FE: fasthash_accum_cstring_aligned (hashfn_unstable.h:299)
==00:00:00:23.391 271086==    by 0x2BE8FE: fasthash_accum_cstring (hashfn_unstable.h:323)
==00:00:00:23.391 271086==    by 0x2BE8FE: spcachekey_hash (namespace.c:268)

See bt-wo-asserts-Og.txt

In addition the -O0 build with asserts gives an error in the
pg_rightmost_one_pos64(), not in the fasthash_accum():
==00:00:00:16.360 100422==    at 0x3424D6: pg_rightmost_one_pos64 (pg_bitutils.h:148)
==00:00:00:16.360 100422==    by 0x342909: fasthash_accum_cstring_aligned (hashfn_unstable.h:298)
==00:00:00:16.360 100422==    by 0x3429AB: fasthash_accum_cstring (hashfn_unstable.h:323)
==00:00:00:16.360 100422==    by 0x342AFC: spcachekey_hash (namespace.c:268)
==00:00:00:16.360 100422==    by 0x3437C2: nsphash_lookup (simplehash.h:836)

See bt-with-asserts-O0.txt, please. It is clear as "word" contains 5 undefined bytes.
(Maybe compiler swallowed this line in -Og build.)
The previous two cases not so clear because valgrind decided that
the "remainder" in the fasthash_accum_cstring_aligned() was undefined.
It thinks that if the argument of __builtin_ctzl() contains some
undefined bytes then the result will be undefined although all rightmost
bits and the first non-zero bit are located in the defined bytes.
On the other hand the presence of the line "Assert(word != 0);"
in the pg_rightmost_one_pos64() already appears to be a
valid reason to use a valgrind-safe solution that will
not allow any undefined bits in its argument.

Besides i found that in the case described above it takes 214
asm instructions to perform "call 0xXXX <spcachekey_hash>" for
existing implementation in the master while the patch from [2]
was a bit faster - 211 instructions.
So i rebased it on the current master and kindly ask to take
it into account as well.

With the best regards,

-- 
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

[1] https://www.postgresql.org/message-id/a3a959f6-14b8-4819-ac04-eaf2aa2e868d%40postgrespro.ru
   
[2] https://www.postgresql.org/message-id/0647027b-9c9a-4f16-8f7c-3f9f3eb9451e%40postgrespro.ru

Attachments:

bt-with-asserts-Og.txt (text/plain, 9.2K) download Program received signal SIGTRAP, Trace/breakpoint trap. 0x00000000003084a3 in fasthash_accum (len=2, k=0x6e312c8 "og", hs=<synthetic pointer>) at ../../../src/include/common/hashfn_unstable.h:142 142 Assert(len <= FH_SIZEOF_ACCUM); (gdb) bt full #0 0x00000000003084a3 in fasthash_accum (len=2, k=0x6e312c8 "og", hs=<synthetic pointer>) at ../../../src/include/common/hashfn_unstable.h:142 lower_four = <optimized out> lower_four = <optimized out> #1 fasthash_accum_cstring_aligned (str=0x6e312c8 "og", hs=<synthetic pointer>) at ../../../src/include/common/hashfn_unstable.h:299 start = 0x6e312c0 "pg_catalog" remainder = 2 zero_byte_low = 9259542121126297600 start = <optimized out> remainder = <optimized out> zero_byte_low = <optimized out> chunk = <optimized out> #2 fasthash_accum_cstring (str=0x6e312c0 "pg_catalog", hs=<synthetic pointer>) at ../../../src/include/common/hashfn_unstable.h:323 len = <optimized out> len_check = 10 hs_check = {accum = <optimized out>, hash = <optimized out>} len = <optimized out> len_check = <optimized out> hs_check = {accum = <optimized out>, hash = <optimized out>} #3 spcachekey_hash (key=...) at namespace.c:268 hs = {accum = <optimized out>, hash = <optimized out>} sp_len = <optimized out> #4 0x0000000000308a3d in nsphash_lookup (key=..., tb=0x6e3f0c0) at ../../../src/include/lib/simplehash.h:836 hash = <optimized out> hash = <optimized out> #5 spcache_insert (searchPath=searchPath@entry=0x6e312c0 "pg_catalog", roleid=roleid@entry=10) at namespace.c:394 entry = <optimized out> cachekey = {searchPath = <optimized out>, roleid = <optimized out>} #6 0x00000000003095da in cachedNamespacePath (searchPath=0x6e312c0 "pg_catalog", roleid=roleid@entry=10) at namespace.c:4251 oldcxt = <optimized out> entry = <optimized out> #7 0x00000000003096c3 in recomputeNamespacePath () at namespace.c:4309 roleid = 10 pathChanged = <optimized out> entry = <optimized out> #8 0x00000000003097b4 in RelnameGetRelid (relname=0x6e03548 "pg_authid") at namespace.c:890 relid = <optimized out> l = <optimized out> #9 0x000000000030af73 in RangeVarGetRelidExtended (relation=0x6e03568, lockmode=lockmode@entry=1, flags=flags@entry=0, callback=callback@entry=0x0, callback_arg=callback_arg@entry=0x0) at namespace.c:539 inval_count = 0 relId = <optimized out> oldRelId = 0 retry = false missing_ok = false __func__ = "RangeVarGetRelidExtended" #10 0x00000000002f0739 in objectNamesToOids (objtype=OBJECT_TABLE, objnames=0x6e035b8, is_grant=false) at aclchk.c:701 relvar = <optimized out> relOid = <optimized out> cell__state = {l = <optimized out>, i = <optimized out>} objects = 0x0 cell = <optimized out> lockmode = 1 #11 0x00000000002f5f00 in ExecuteGrantStmt (stmt=stmt@entry=0x6e03680) at aclchk.c:425 istmt = {is_grant = false, objtype = OBJECT_TABLE, objects = 0x0, all_privs = 48, privileges = 115357312, col_privs = 0x1ffeffea90, grantees = 0x7abd11 <EventCacheLookup+50>, grant_option = 255, behavior = (DROP_CASCADE | unknown: 0xfffffffe)} cell = <optimized out> errormsg = <optimized out> all_privileges = <optimized out> __func__ = "ExecuteGrantStmt" #12 0x000000000065e2e8 in ProcessUtilitySlow (pstate=pstate@entry=0x6f9a490, pstmt=pstmt@entry=0x6e03730, queryString=queryString@entry=0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n", context=context@entry=PROCESS_UTILITY_TOPLEVEL, params=params@entry=0x0, queryEnv=queryEnv@entry=0x0, dest=0xb69740 <debugtupDR>, qc=0x1ffefff0a0) at utility.c:1812 _save_exception_stack = 0x1ffeffef60 _save_context_stack = 0x0 _local_sigjmp_buf = {{__jmpbuf = {117023888, 2018119622333043965, 0, 115357488, 115357312, 0, 2018119622479844605, 2035117059389658365}, __mask_was_saved = 0, __saved_mask = {__val = {117023872, 16, 0, 0, 0, 1296236544, 117024128, 16, 0, 0, 0, 1296236544, 117023872, 16, 0, 0}}}} _do_rethrow = false parsetree = 0x6e03680 isTopLevel = true isCompleteQuery = true needCleanup = false commandCollected = false address = {classId = 4278184864, objectId = 31, objectSubId = -16782448} secondaryObject = {classId = 0, objectId = 0, objectSubId = 0} __func__ = "ProcessUtilitySlow" #13 0x000000000065ccb3 in standard_ProcessUtility (pstmt=0x6e03730, queryString=0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n", readOnlyTree=<optimized out>, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xb69740 <debugtupDR>, qc=0x1ffefff0a0) at utility.c:969 stmt = 0x6e03680 parsetree = 0x6e03680 isTopLevel = true isAtomicContext = false pstate = 0x6f9a490 readonly_flags = <optimized out> __func__ = "standard_ProcessUtility" #14 0x000000000065cf85 in ProcessUtility (pstmt=pstmt@entry=0x6e03730, queryString=<optimized out>, readOnlyTree=<optimized out>, context=<optimized out>, params=<optimized out>, queryEnv=<optimized out>, dest=0xb69740 <debugtupDR>, qc=0x1ffefff0a0) at utility.c:523 No locals. #15 0x000000000065a427 in PortalRunUtility (portal=portal@entry=0x6fbaaa0, pstmt=pstmt@entry=0x6e03730, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xb69740 <debugtupDR>, qc=qc@entry=0x1ffefff0a0) at pquery.c:1152 No locals. #16 0x000000000065a72d in PortalRunMulti (portal=portal@entry=0x6fbaaa0, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xb69740 <debugtupDR>, altdest=altdest@entry=0xb69740 <debugtupDR>, qc=qc@entry=0x1ffefff0a0) at pquery.c:1309 pstmt = 0x6e03730 stmtlist_item__state = {l = <optimized out>, i = <optimized out>} active_snapshot_set = false stmtlist_item = 0x6e03a98 #17 0x000000000065ab2c in PortalRun (portal=portal@entry=0x6fbaaa0, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, dest=dest@entry=0xb69740 <debugtupDR>, altdest=altdest@entry=0xb69740 <debugtupDR>, qc=qc@entry=0x1ffefff0a0) at pquery.c:787 _save_exception_stack = 0x1ffefff1b0 _save_context_stack = 0x0 _local_sigjmp_buf = {{__jmpbuf = {0, 2018119622158980349, 117156512, 115357392, 0, 115357440, 2018119622349821181, 2035117056493622525}, __mask_was_saved = 0, __saved_mask = {__val = {117164768, 10556638, 1, 137422172183, 115357440, 137422172160, 8214643, 117156512, 10556638, 1, 1, 137422172224, 8389872, 137422172224, 10175009201158647808, 115357464}}}} _do_rethrow = <optimized out> result = <optimized out> nprocessed = <optimized out> saveTopTransactionResourceOwner = 0x6ec93b8 saveTopTransactionContext = 0x6fe8d00 saveActivePortal = 0x0 saveResourceOwner = 0x6ec93b8 savePortalContext = 0x0 saveMemoryContext = 0x6fe8d00 __func__ = "PortalRun" #18 0x000000000065693a in exec_simple_query (query_string=query_string@entry=0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n") at postgres.c:1271 cmdtaglen = 6 snapshot_set = <optimized out> per_parsetree_context = 0x0 plantree_list = 0x6e03a80 parsetree = 0x6e036d0 commandTag = <optimized out> qc = {commandTag = CMDTAG_UNKNOWN, nprocessed = 0} querytree_list = <optimized out> portal = 0x6fbaaa0 receiver = 0xb69740 <debugtupDR> format = 0 cmdtagname = <optimized out> parsetree_item__state = {l = <optimized out>, i = <optimized out>} dest = DestDebug oldcontext = 0x6fe8d00 parsetree_list = 0x6e03700 parsetree_item = 0x6e03718 save_log_statement_stats = false was_logged = false use_implicit_block = false msec_str = "`+\340\006\000\000\000\000`\361\377\376\037\000\000\000\f", '\000' <repeats 14 times> __func__ = "exec_simple_query" #19 0x0000000000658af5 in PostgresMain (dbname=<optimized out>, username=username@entry=0x6e16130 "postgres") at postgres.c:4691 query_string = 0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n" firstchar = <optimized out> input_message = {data = 0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n", len = 38, maxlen = 1024, cursor = 38} local_sigjmp_buf = {{__jmpbuf = {115584336, 2018119622223992061, 115433776, 12, 0, 0, 2018119622205117693, 2035117057862145277}, __mask_was_saved = 1, __saved_mask = {__val = {0, 137422172784, 8383051, 137422172816, 18446744073709551615, 4869, 115337696, 116000232, 17408, 0, 0, 12, 10175009201158647808, 115337696, 115433776, 137422172816}}}} send_ready_for_query = false idle_in_transaction_timeout_enabled = false idle_session_timeout_enabled = false __func__ = "PostgresMain" #20 0x0000000000659044 in PostgresSingleUserMain (argc=argc@entry=12, argv=argv@entry=0x6dfe520, username=0x6e16130 "postgres") at postgres.c:4130 dbname = 0x6e3ad50 "template1" __func__ = "PostgresSingleUserMain" #21 0x00000000004ad10a in main (argc=12, argv=0x6dfe520) at main.c:226 do_check_root = <optimized out> dispatch_option = <optimized out>
bt-wo-asserts-Og.txt (text/plain, 9.1K) download Program received signal SIGTRAP, Trace/breakpoint trap. 0x00000000002be8fe in fasthash_accum (len=2, k=0x6e312c8 "og", hs=<synthetic pointer>) at ../../../src/include/common/hashfn_unstable.h:180 180 switch (len) (gdb) bt full #0 0x00000000002be8fe in fasthash_accum (len=2, k=0x6e312c8 "og", hs=<synthetic pointer>) at ../../../src/include/common/hashfn_unstable.h:180 lower_four = <optimized out> lower_four = <optimized out> #1 fasthash_accum_cstring_aligned (str=0x6e312c8 "og", hs=<optimized out>) at ../../../src/include/common/hashfn_unstable.h:299 start = <optimized out> remainder = 2 zero_byte_low = 9259542121126297600 start = <optimized out> remainder = <optimized out> zero_byte_low = <optimized out> chunk = <optimized out> #2 fasthash_accum_cstring (str=0x6e312c0 "pg_catalog", hs=<synthetic pointer>) at ../../../src/include/common/hashfn_unstable.h:323 len = <optimized out> len = <optimized out> #3 spcachekey_hash (key=...) at namespace.c:268 hs = {accum = <optimized out>, hash = <optimized out>} sp_len = <optimized out> hs = {accum = <optimized out>, hash = <optimized out>} sp_len = <optimized out> #4 nsphash_lookup (key=..., tb=0x6e3f0c0) at ../../../src/include/lib/simplehash.h:836 hash = <optimized out> hash = <optimized out> #5 spcache_insert (searchPath=searchPath@entry=0x6e312c0 "pg_catalog", roleid=roleid@entry=10) at namespace.c:394 entry = <optimized out> cachekey = {searchPath = <optimized out>, roleid = <optimized out>} #6 0x00000000002bfc5b in cachedNamespacePath (searchPath=0x6e312c0 "pg_catalog", roleid=roleid@entry=10) at namespace.c:4251 oldcxt = <optimized out> entry = <optimized out> #7 0x00000000002bfd44 in recomputeNamespacePath () at namespace.c:4309 roleid = 10 pathChanged = <optimized out> entry = <optimized out> #8 0x00000000002bfe35 in RelnameGetRelid (relname=0x6e03548 "pg_authid") at namespace.c:890 relid = <optimized out> l = <optimized out> #9 0x00000000002c14e1 in RangeVarGetRelidExtended (relation=0x6e03568, lockmode=lockmode@entry=1, flags=flags@entry=0, callback=callback@entry=0x0, callback_arg=callback_arg@entry=0x0) at namespace.c:539 inval_count = 0 relId = <optimized out> oldRelId = 0 retry = false missing_ok = false __func__ = "RangeVarGetRelidExtended" #10 0x00000000002a87dc in objectNamesToOids (objtype=<optimized out>, objnames=0x6e035b8, is_grant=false) at aclchk.c:701 relvar = <optimized out> relOid = <optimized out> cell__state = {l = <optimized out>, i = <optimized out>} objects = 0x0 cell = <optimized out> lockmode = 1 #11 0x00000000002adbf9 in ExecuteGrantStmt (stmt=stmt@entry=0x6e03680) at aclchk.c:425 istmt = {is_grant = false, objtype = OBJECT_TABLE, objects = 0x0, all_privs = 48, privileges = 115357312, col_privs = 0x1ffeffea90, grantees = 0x6e82cb <EventCacheLookup+50>, grant_option = 255, behavior = (DROP_CASCADE | unknown: 0xfffffffe)} cell = <optimized out> errormsg = <optimized out> all_privileges = <optimized out> __func__ = "ExecuteGrantStmt" #12 0x00000000005b2c30 in ProcessUtilitySlow (pstate=pstate@entry=0x6f9a490, pstmt=pstmt@entry=0x6e03730, queryString=queryString@entry=0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n", context=context@entry=PROCESS_UTILITY_TOPLEVEL, params=params@entry=0x0, queryEnv=queryEnv@entry=0x0, dest=0xa5d760 <debugtupDR>, qc=0x1ffefff0a0) at utility.c:1812 _save_exception_stack = 0x1ffeffef60 _save_context_stack = 0x0 _local_sigjmp_buf = {{__jmpbuf = {117023888, -2063849044308330718, 0, 115357488, 115357312, 0, -2063849044429965534, -2061450765248563422}, __mask_was_saved = 0, __saved_mask = {__val = {117023872, 16, 0, 0, 0, 1296236544, 117024128, 16, 0, 0, 0, 1296236544, 117023872, 16, 0, 0}}}} _do_rethrow = false parsetree = 0x6e03680 isTopLevel = true isCompleteQuery = true needCleanup = false commandCollected = false address = {classId = 4278184864, objectId = 31, objectSubId = -16782448} secondaryObject = {classId = 0, objectId = 0, objectSubId = 0} __func__ = "ProcessUtilitySlow" #13 0x00000000005b180d in standard_ProcessUtility (pstmt=0x6e03730, queryString=0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n", readOnlyTree=<optimized out>, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xa5d760 <debugtupDR>, qc=0x1ffefff0a0) at utility.c:969 stmt = 0x6e03680 parsetree = 0x6e03680 isTopLevel = true isAtomicContext = false pstate = 0x6f9a490 readonly_flags = <optimized out> __func__ = "standard_ProcessUtility" #14 0x00000000005b1a5f in ProcessUtility (pstmt=pstmt@entry=0x6e03730, queryString=<optimized out>, readOnlyTree=<optimized out>, context=<optimized out>, params=<optimized out>, queryEnv=<optimized out>, dest=0xa5d760 <debugtupDR>, qc=0x1ffefff0a0) at utility.c:523 No locals. #15 0x00000000005af30c in PortalRunUtility (portal=portal@entry=0x6fbaaa0, pstmt=pstmt@entry=0x6e03730, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xa5d760 <debugtupDR>, qc=qc@entry=0x1ffefff0a0) at pquery.c:1152 No locals. #16 0x00000000005af55c in PortalRunMulti (portal=portal@entry=0x6fbaaa0, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xa5d760 <debugtupDR>, altdest=altdest@entry=0xa5d760 <debugtupDR>, qc=qc@entry=0x1ffefff0a0) at pquery.c:1309 pstmt = 0x6e03730 stmtlist_item__state = {l = <optimized out>, i = <optimized out>} active_snapshot_set = false stmtlist_item = 0x6e03a98 #17 0x00000000005af85f in PortalRun (portal=portal@entry=0x6fbaaa0, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, dest=dest@entry=0xa5d760 <debugtupDR>, altdest=altdest@entry=0xa5d760 <debugtupDR>, qc=qc@entry=0x1ffefff0a0) at pquery.c:787 _save_exception_stack = 0x1ffefff1b0 _save_context_stack = 0x0 _local_sigjmp_buf = {{__jmpbuf = {0, -2063849044213958878, 10868576, 115357392, 0, 115357440, -2063849044291553502, -2061450777208359134}, __mask_was_saved = 0, __saved_mask = {__val = {117164768, 9483622, 1, 137422172183, 115357440, 137422172160, 7397230, 117156512, 9483622, 1, 1, 137422172224, 7547098, 115354464, 2504669645130645504, 117156512}}}} _do_rethrow = <optimized out> result = <optimized out> nprocessed = <optimized out> saveTopTransactionResourceOwner = 0x6ec93b8 saveTopTransactionContext = 0x6fe8d00 saveActivePortal = 0x0 saveResourceOwner = 0x6ec93b8 savePortalContext = 0x0 saveMemoryContext = 0x6fe8d00 __func__ = "PortalRun" #18 0x00000000005abae2 in exec_simple_query (query_string=query_string@entry=0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n") at postgres.c:1271 cmdtaglen = 6 snapshot_set = <optimized out> per_parsetree_context = 0x0 plantree_list = <optimized out> parsetree = 0x6e036d0 commandTag = CMDTAG_REVOKE qc = {commandTag = CMDTAG_UNKNOWN, nprocessed = 0} querytree_list = <optimized out> portal = 0x6fbaaa0 receiver = 0xa5d760 <debugtupDR> format = 0 cmdtagname = <optimized out> parsetree_item__state = {l = <optimized out>, i = <optimized out>} dest = DestDebug oldcontext = 0x6fe8d00 parsetree_list = 0x6e03700 parsetree_item = 0x6e03718 save_log_statement_stats = false was_logged = false use_implicit_block = false msec_str = "`+\340\006\000\000\000\000`\361\377\376\037\000\000\000\f", '\000' <repeats 14 times> __func__ = "exec_simple_query" #19 0x00000000005adc2c in PostgresMain (dbname=<optimized out>, username=username@entry=0x6e16130 "postgres") at postgres.c:4691 query_string = 0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n" firstchar = <optimized out> input_message = {data = 0x6e02b60 "REVOKE ALL ON pg_authid FROM public;\n", len = 38, maxlen = 1024, cursor = 38} local_sigjmp_buf = {{__jmpbuf = {115584336, -2063849044165724382, 115433776, 12, 0, 0, -2063849044184598750, -2061450776201464030}, __mask_was_saved = 1, __saved_mask = {__val = {0, 1006, 18446744073709551615, 4869, 115337696, 116000232, 17408, 0, 0, 1048564, 2504669645130645504, 12, 115337696, 115433776, 12, 137422172816}}}} send_ready_for_query = false idle_in_transaction_timeout_enabled = false idle_session_timeout_enabled = false __func__ = "PostgresMain" #20 0x00000000005ae132 in PostgresSingleUserMain (argc=argc@entry=12, argv=argv@entry=0x6dfe520, username=0x6e16130 "postgres") at postgres.c:4130 dbname = 0x6e3ad50 "template1" __func__ = "PostgresSingleUserMain" #21 0x0000000000438ef2 in main (argc=12, argv=0x6dfe520) at main.c:226 do_check_root = <optimized out> dispatch_option = <optimized out>
bt-with-asserts-O0.txt (text/plain, 8.2K) download Program received signal SIGTRAP, Trace/breakpoint trap. 0x00000000003424d6 in pg_rightmost_one_pos64 (word=9259542121126297600) at ../../../src/include/port/pg_bitutils.h:148 148 Assert(word != 0); (gdb) bt full #0 0x00000000003424d6 in pg_rightmost_one_pos64 (word=9259542121126297600) at ../../../src/include/port/pg_bitutils.h:148 No locals. #1 0x000000000034290a in fasthash_accum_cstring_aligned (hs=0x1ffeffe5b0, str=0x6e312c8 "og") at ../../../src/include/common/hashfn_unstable.h:298 start = 0x6e312c0 "pg_catalog" remainder = 115544768 zero_byte_low = 9259542121126297600 #2 0x00000000003429ac in fasthash_accum_cstring (hs=0x1ffeffe5b0, str=0x6e312c0 "pg_catalog") at ../../../src/include/common/hashfn_unstable.h:323 len = 0 len_check = 10 hs_check = {accum = 26479, hash = 4431955251355380062} #3 0x0000000000342afd in spcachekey_hash (key=...) at namespace.c:268 hs = {accum = 7809651190464997232, hash = 9554609706923330532} sp_len = 0 #4 0x00000000003437c3 in nsphash_lookup (tb=0x71e5e00, key=...) at ../../../src/include/lib/simplehash.h:836 hash = 0 #5 0x00000000003439d6 in spcache_insert (searchPath=0x6e312c0 "pg_catalog", roleid=10) at namespace.c:394 entry = 0x71e5d00 cachekey = {searchPath = 0x6e312c0 "pg_catalog", roleid = 10} #6 0x0000000000349b89 in cachedNamespacePath (searchPath=0x6e312c0 "pg_catalog", roleid=10) at namespace.c:4251 oldcxt = 0x6ec4f88 entry = 0x6fd8858 #7 0x0000000000349cc2 in recomputeNamespacePath () at namespace.c:4309 roleid = 10 pathChanged = false entry = 0xc0a58cfefe9b00 #8 0x000000000034458e in RelnameGetRelid (relname=0x6efff68 "pg_authid") at namespace.c:890 relid = 3466 l = 0x100000000000000 #9 0x0000000000343ccc in RangeVarGetRelidExtended (relation=0x6efff88, lockmode=1, flags=0, callback=0x0, callback_arg=0x0) at namespace.c:539 inval_count = 0 relId = 4278183792 oldRelId = 0 retry = false missing_ok = false __func__ = "RangeVarGetRelidExtended" #10 0x00000000003240ed in objectNamesToOids (objtype=OBJECT_TABLE, objnames=0x6efffd8, is_grant=false) at aclchk.c:701 relvar = 0x6efff88 relOid = 0 cell__state = {l = 0x6efffd8, i = 0} objects = 0x0 cell = 0x6effff0 lockmode = 1 #11 0x0000000000323814 in ExecuteGrantStmt (stmt=0x6f000a0) at aclchk.c:425 istmt = {is_grant = false, objtype = OBJECT_TABLE, objects = 0x0, all_privs = 144, privileges = 4358515, col_privs = 0x1ffeffe8b0, grantees = 0x42801d <EventTriggerBeginCompleteQuery+17>, grant_option = 112, behavior = DROP_RESTRICT} cell = 0x0 errormsg = 0x71b4ad0 "~", '\177' <repeats 199 times>... all_privileges = 137422170220 __func__ = "ExecuteGrantStmt" #12 0x00000000007cf762 in ProcessUtilitySlow (pstate=0x71b49e0, pstmt=0x6f00150, queryString=0x6eff580 "REVOKE ALL ON pg_authid FROM public;\n", context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xdfcca0 <debugtupDR>, qc=0x1ffefff090) at utility.c:1812 _save_exception_stack = 0x1ffeffef10 _save_context_stack = 0x0 _local_sigjmp_buf = {{__jmpbuf = {0, 4259416265021831164, 1991968, 137422173200, 0, 0, 4259416265145563132, 4261392063212664828}, __mask_was_saved = 0, __saved_mask = {__val = {0, 1296236544, 117345944, 24, 0, 0, 0, 1296236544, 117345824, 16, 0, 0, 0, 0, 54225220520549120, 137422171344}}}} _do_rethrow = false parsetree = 0x6f000a0 isTopLevel = true isCompleteQuery = true needCleanup = false commandCollected = false address = {classId = 117345944, objectId = 0, objectSubId = 1} secondaryObject = {classId = 0, objectId = 0, objectSubId = 0} __func__ = "ProcessUtilitySlow" #13 0x00000000007cd8a4 in standard_ProcessUtility (pstmt=0x6f00150, queryString=0x6eff580 "REVOKE ALL ON pg_authid FROM public;\n", readOnlyTree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xdfcca0 <debugtupDR>, qc=0x1ffefff090) at utility.c:969 stmt = 0x6f000a0 parsetree = 0x6f000a0 isTopLevel = true isAtomicContext = false pstate = 0x71b49e0 readonly_flags = 0 __func__ = "standard_ProcessUtility" #14 0x00000000007ccbc1 in ProcessUtility (pstmt=0x6f00150, queryString=0x6eff580 "REVOKE ALL ON pg_authid FROM public;\n", readOnlyTree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xdfcca0 <debugtupDR>, qc=0x1ffefff090) at utility.c:523 No locals. #15 0x00000000007cb624 in PortalRunUtility (portal=0x6fbaaa0, pstmt=0x6f00150, isTopLevel=true, setHoldSnapshot=false, dest=0xdfcca0 <debugtupDR>, qc=0x1ffefff090) at pquery.c:1152 No locals. #16 0x00000000007cb89e in PortalRunMulti (portal=0x6fbaaa0, isTopLevel=true, setHoldSnapshot=false, dest=0xdfcca0 <debugtupDR>, altdest=0xdfcca0 <debugtupDR>, qc=0x1ffefff090) at pquery.c:1309 pstmt = 0x6f00150 stmtlist_item__state = {l = 0x6f004a0, i = 0} active_snapshot_set = false stmtlist_item = 0x6f004b8 #17 0x00000000007caced in PortalRun (portal=0x6fbaaa0, count=9223372036854775807, isTopLevel=true, dest=0xdfcca0 <debugtupDR>, altdest=0xdfcca0 <debugtupDR>, qc=0x1ffefff090) at pquery.c:787 _save_exception_stack = 0x1ffefff1d0 _save_context_stack = 0x0 _local_sigjmp_buf = {{__jmpbuf = {0, 4259416265049094140, 1991968, 137422173200, 0, 0, 4259416265072162812, 4261392059674507260}, __mask_was_saved = 0, __saved_mask = {__val = {10311311, 64, 54225220520549120, 137422172064, 10315239, 137422172103, 4411134904, 13045126, 119228640, 137422172128, 10546663, 0, 137422172174, 4294967296, 117345536, 137422173200}}}} _do_rethrow = false result = false nprocessed = 137422173200 saveTopTransactionResourceOwner = 0x6ec93b8 saveTopTransactionContext = 0x6fe8d00 saveActivePortal = 0x0 saveResourceOwner = 0x6ec93b8 savePortalContext = 0x0 saveMemoryContext = 0x6fe8d00 __func__ = "PortalRun" #18 0x00000000007c3750 in exec_simple_query (query_string=0x6eff580 "REVOKE ALL ON pg_authid FROM public;\n") at postgres.c:1271 cmdtaglen = 6 snapshot_set = false per_parsetree_context = 0x0 plantree_list = 0x6f004a0 parsetree = 0x6f000f0 commandTag = CMDTAG_REVOKE qc = {commandTag = CMDTAG_UNKNOWN, nprocessed = 0} querytree_list = 0x6f00470 portal = 0x6fbaaa0 receiver = 0xdfcca0 <debugtupDR> format = 0 cmdtagname = 0xc09ced "REVOKE" parsetree_item__state = {l = 0x6f00120, i = 0} dest = DestDebug oldcontext = 0x6fe8d00 parsetree_list = 0x6f00120 parsetree_item = 0x6f00138 save_log_statement_stats = false was_logged = false use_implicit_block = false msec_str = "\320\360\377\376\037\000\000\000\020\263W\000\000\000\000\000\061\243\247\300\357\320\002\000\200\361\377\376\037\000\000" __func__ = "exec_simple_query" #19 0x00000000007c8b38 in PostgresMain (dbname=0x6e3ad50 "template1", username=0x6e16130 "postgres") at postgres.c:4691 query_string = 0x6eff580 "REVOKE ALL ON pg_authid FROM public;\n" firstchar = 81 input_message = {data = 0x6eff580 "REVOKE ALL ON pg_authid FROM public;\n", len = 38, maxlen = 1024, cursor = 38} local_sigjmp_buf = {{__jmpbuf = {10849024, 4259416265479010300, 1991968, 137422173200, 0, 0, 4259416265418192892, 4261392060253976572}, __mask_was_saved = 1, __saved_mask = {__val = {0, 115337696, 116000232, 4869, 115337696, 116000232, 17408, 0, 115337696, 0, 115337696, 137422172816, 7970104, 0, 115337696, 137422172848}}}} send_ready_for_query = false idle_in_transaction_timeout_enabled = false idle_session_timeout_enabled = false __func__ = "PostgresMain" #20 0x00000000007c810c in PostgresSingleUserMain (argc=12, argv=0x6dfe520, username=0x6e16130 "postgres") at postgres.c:4130 dbname = 0x6e3ad50 "template1" __func__ = "PostgresSingleUserMain" #21 0x000000000057c202 in main (argc=12, argv=0x6dfe520) at main.c:226 do_check_root = true dispatch_option = DISPATCH_SINGLE
v3-0001-Add-valgrind-safe-code-to-find-rightmost-bytes.patch (text/x-patch, 1.5K) download From a04e825e776ebb5684a94a310b1dc2c54e515d0c Mon Sep 17 00:00:00 2001 From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru> Date: Wed, 12 Feb 2025 20:22:45 +0300 Subject: [PATCH] Use valgrind-safe code to find a number of rightmost zero bytes. --- src/include/common/hashfn_unstable.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h index e07c0226c1f..82158f0d9c3 100644 --- a/src/include/common/hashfn_unstable.h +++ b/src/include/common/hashfn_unstable.h @@ -255,7 +255,7 @@ static inline size_t fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str) { const char *const start = str; - size_t remainder; + size_t remainder = 0; uint64 zero_byte_low; Assert(PointerIsAligned(start, uint64)); @@ -291,11 +291,18 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str) } /* - * The byte corresponding to the NUL will be 0x80, so the rightmost bit - * position will be in the range 7, 15, ..., 63. Turn this into byte - * position by dividing by 8. + * The byte corresponding to the NUL terminator will be the rightmost 0x80. + * pAll zero bytes to the right of it correspond to the tail of the string. + * It remains to count them. */ - remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE; + while ((zero_byte_low & 0xFF) == 0) + { + zero_byte_low >>= 8; + ++remainder; + } + + Assert(remainder != 0); + fasthash_accum(hs, str, remainder); str += remainder; -- 2.48.1

view thread (103+ messages)  latest in thread

Message-ID: <f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru>
Permalink:  ../f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru/
Also on:    postgresql.org/message-id/f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: a.melnikov@postgrespro.ru, johncnaylorls@gmail.com, tgl@sss.pgh.pa.us, pgsql@j-davis.com, ants.aasma@cybertec.at, hlinnaka@iki.fi, zhjwpku@gmail.com, jian.universality@gmail.com, andres@anarazel.de, gurjeet@singh.im
  Subject: Re: Change GUC hashtable to use simplehash?
  In-Reply-To: <f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru>
  References: <c95e1821b6a69ec0c40eb0252e037b68a62cdae3.camel@j-davis.com> <CANWCAZbwvp7oUEkbw-xP4L0_S_WNKq-J-ucP4RCNDPJnrakUPw@mail.gmail.com> <458350a908d9607f7fc2a15407f4405cc454c970.camel@j-davis.com> <CANWCAZYxrJJ4EDw=o5vu_gAs7dS_PK6ry0rqkVu9opGpAJjoQQ@mail.gmail.com> <2b0df3af97fac73a40aba16a58837e2cee594b1f.camel@j-davis.com> <CANWCAZYLvWOm-1XLT8wGoXGgNBEV_NPMWJY4gM6cXa7LHVDjtw@mail.gmail.com> <a3a959f6-14b8-4819-ac04-eaf2aa2e868d@postgrespro.ru> <CANWCAZZ0ptKxEyO504OjZOr3Co=WaSEQG5eUU-TFmqD4twhe_w@mail.gmail.com> <0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru> <1520769.1736991361@sss.pgh.pa.us> <16198d33-a4e2-46db-b6c3-494367f5816d@postgrespro.ru> <CANWCAZbg_pN72nwaeq5pyBOV__Cbs2=HoUPh8NJW3LuF48JkQw@mail.gmail.com> <CANWCAZY6rFYeFGGoW_eCVpubQ-QNtkbuumWQts-9FU8Qtc65cQ@mail.gmail.com> <4c739718-27d6-44fe-9113-56a251c13275@postgrespro.ru> <CANWCAZai=YQNV_VY6tt=pL2RquU2NNr2WQbuj3G8hYeJBeGyyA@mail.gmail.com> <f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox