{"action":"opened","issue":{"url":"https://api.github.com/repos/pg-strom/devel/issues/191","labels_url":"https://api.github.com/repos/pg-strom/devel/issues/191/labels{/name}","comments_url":"https://api.github.com/repos/pg-strom/devel/issues/191/comments","events_url":"https://api.github.com/repos/pg-strom/devel/issues/191/events","html_url":"https://github.com/pg-strom/devel/issues/191","id":104223853,"number":191,"title":"(JP) Gpuでnow()関数を実行しようとするとセグメンテーションフォルト","user":{"login":"onlyindreams","id":7244786,"avatar_url":"https://avatars.githubusercontent.com/u/7244786?v=3","gravatar_id":"","url":"https://api.github.com/users/onlyindreams","html_url":"https://github.com/onlyindreams","followers_url":"https://api.github.com/users/onlyindreams/followers","following_url":"https://api.github.com/users/onlyindreams/following{/other_user}","gists_url":"https://api.github.com/users/onlyindreams/gists{/gist_id}","starred_url":"https://api.github.com/users/onlyindreams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onlyindreams/subscriptions","organizations_url":"https://api.github.com/users/onlyindreams/orgs","repos_url":"https://api.github.com/users/onlyindreams/repos","events_url":"https://api.github.com/users/onlyindreams/events{/privacy}","received_events_url":"https://api.github.com/users/onlyindreams/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pg-strom/devel/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"kaigai","id":216210,"avatar_url":"https://avatars.githubusercontent.com/u/216210?v=3","gravatar_id":"","url":"https://api.github.com/users/kaigai","html_url":"https://github.com/kaigai","followers_url":"https://api.github.com/users/kaigai/followers","following_url":"https://api.github.com/users/kaigai/following{/other_user}","gists_url":"https://api.github.com/users/kaigai/gists{/gist_id}","starred_url":"https://api.github.com/users/kaigai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaigai/subscriptions","organizations_url":"https://api.github.com/users/kaigai/orgs","repos_url":"https://api.github.com/users/kaigai/repos","events_url":"https://api.github.com/users/kaigai/events{/privacy}","received_events_url":"https://api.github.com/users/kaigai/received_events","type":"User","site_admin":false},"milestone":null,"comments":0,"created_at":"2015-09-01T09:21:41Z","updated_at":"2015-09-01T09:21:41Z","closed_at":null,"body":"再現クエリ\r\n```\r\npsql -a << EOF\r\nset pg_strom.gpu_setup_cost = 0;\r\ndrop table if exists t1;\r\ncreate table t1 as select generate_series(now() - '30 days'::interval,now(), '1 days') as c1;\r\nexplain select c1 from t1 where c1 < now();\r\nexplain select c1 from t1 where c1 < now();\r\nEOF\r\n```\r\n\r\n実行結果\r\n```\r\n[nanzai@saba debug_strom]$ psql -a << EOF\r\n> set pg_strom.gpu_setup_cost = 0;\r\n> drop table if exists t1;\r\n> create table t1 as select generate_series(now() - '30 days'::interval,now(), '1 days') as c1;\r\n> explain select c1 from t1 where c1 < now();\r\n> explain select c1 from t1 where c1 < now();\r\n> EOF\r\nset pg_strom.gpu_setup_cost = 0;\r\nSET\r\ndrop table if exists t1;\r\nDROP TABLE\r\ncreate table t1 as select generate_series(now() - '30 days'::interval,now(), '1 days') as c1;\r\nSELECT 31\r\nexplain select c1 from t1 where c1 < now();\r\n                     QUERY PLAN                      \r\n-----------------------------------------------------\r\n Seq Scan on t1  (cost=0.00..43.90 rows=753 width=8)\r\n   Filter: (c1 < now())\r\n(2 rows)\r\n\r\nexplain select c1 from t1 where c1 < now();\r\nserver closed the connection unexpectedly\r\n        This probably means the server terminated abnormally\r\n        before or while processing the request.\r\nconnection to server was lost\r\n2015-09-01 18:09:57 JST   478 LOG:  00000: server process (PID 489) was terminated by signal 11: Segmentation fault\r\n2015-09-01 18:09:57 JST   478 DETAIL:  Failed process was running: explain select c1 from t1 where c1 < now();\r\n2015-09-01 18:09:57 JST   478 LOCATION:  LogChildExit, postmaster.c:3429\r\n2015-09-01 18:09:57 JST   478 LOG:  00000: terminating any other active server processes\r\n2015-09-01 18:09:57 JST   478 LOCATION:  HandleChildCrash, postmaster.c:3146\r\n2015-09-01 18:09:57 JST   485 WARNING:  57P02: terminating connection because of crash of another server process\r\n2015-09-01 18:09:57 JST   485 DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.\r\n2015-09-01 18:09:57 JST   485 HINT:  In a moment you should be able to reconnect to the database and repeat your command.\r\n2015-09-01 18:09:57 JST   485 LOCATION:  quickdie, postgres.c:2612\r\n[nanzai@saba debug_strom]$ 2015-09-01 18:09:57 JST   478 LOG:  00000: all server processes terminated; reinitializing\r\n2015-09-01 18:09:57 JST   478 LOCATION:  PostmasterStateMachine, postmaster.c:3674\r\n2015-09-01 18:09:57 JST   490 LOG:  00000: database system was interrupted; last known up at 2015-09-01 18:09:37 JST\r\n2015-09-01 18:09:57 JST   490 LOCATION:  StartupXLOG, xlog.c:5961\r\n2015-09-01 18:09:57 JST   490 LOG:  00000: database system was not properly shut down; automatic recovery in progress\r\n2015-09-01 18:09:57 JST   490 LOCATION:  StartupXLOG, xlog.c:6436\r\n2015-09-01 18:09:57 JST   490 LOG:  00000: redo starts at 3/48D1BC88\r\n2015-09-01 18:09:57 JST   490 LOCATION:  StartupXLOG, xlog.c:6700\r\n2015-09-01 18:09:57 JST   490 LOG:  00000: invalid record length at 3/48D35850\r\n2015-09-01 18:09:57 JST   490 LOCATION:  ReadRecord, xlog.c:3960\r\n2015-09-01 18:09:57 JST   490 LOG:  00000: redo done at 3/48D35828\r\n2015-09-01 18:09:57 JST   490 LOCATION:  StartupXLOG, xlog.c:6952\r\n2015-09-01 18:09:57 JST   490 LOG:  00000: last completed transaction was at log time 2015-09-01 18:09:57.617298+09\r\n2015-09-01 18:09:57 JST   490 LOCATION:  StartupXLOG, xlog.c:6957\r\n2015-09-01 18:09:57 JST   490 LOG:  00000: MultiXact member wraparound protections are now enabled\r\n2015-09-01 18:09:57 JST   490 LOCATION:  DetermineSafeOldestOffset, multixact.c:2601\r\n2015-09-01 18:09:57 JST   478 LOG:  00000: database system is ready to accept connections\r\n2015-09-01 18:09:57 JST   478 LOCATION:  reaper, postmaster.c:2739\r\n2015-09-01 18:09:57 JST   494 LOG:  00000: autovacuum launcher started\r\n2015-09-01 18:09:57 JST   494 LOCATION:  AutoVacLauncherMain, autovacuum.c:413\r\n```\r\n\r\nバックトレース\r\n```\r\nProgram terminated with signal 11, Segmentation fault.\r\n#0  0x00007f8d531914b1 in pgstrom_devfunc_lookup_by_name (func_name=0x7f8d5a815b20 \"now\", func_namespace=11, func_nargs=0, func_argtypes=0x7f8d5a815ba4, \r\n    func_rettype=1184, func_collid=0, devfn_expr=0x0) at src/codegen.c:1024\r\n1024                            Assert(entry->func_rettype->type_oid == func_rettype);\r\nMissing separate debuginfos, use: debuginfo-install glibc-2.17-55.el7.x86_64 xorg-x11-drv-nvidia-libs-346.46-1.el7.x86_64\r\n(gdb) bt\r\n#0  0x00007f8d531914b1 in pgstrom_devfunc_lookup_by_name (func_name=0x7f8d5a815b20 \"now\", func_namespace=11, func_nargs=0, func_argtypes=0x7f8d5a815ba4, \r\n    func_rettype=1184, func_collid=0, devfn_expr=0x0) at src/codegen.c:1024\r\n#1  0x00007f8d53191bfd in pgstrom_devfunc_lookup (func_oid=1299, func_collid=0) at src/codegen.c:1196\r\n#2  0x00007f8d53193958 in pgstrom_codegen_available_expression (expr=0x1768060) at src/codegen.c:1898\r\n#3  0x00007f8d53193766 in pgstrom_codegen_available_expression (expr=0x1768028) at src/codegen.c:1855\r\n#4  0x00007f8d53193a74 in pgstrom_codegen_available_expression (expr=0x17680e0) at src/codegen.c:1916\r\n#5  0x00007f8d531a5dd8 in gpuscan_add_scan_path (root=0x1767c80, baserel=0x1768268, rtindex=1, rte=0x1767538) at src/gpuscan.c:242\r\n#6  0x00000000006ef5a1 in set_rel_pathlist (root=0x1767c80, rel=0x1768268, rti=1, rte=0x1767538) at allpaths.c:434\r\n#7  0x00000000006ef1e3 in set_base_rel_pathlists (root=0x1767c80) at allpaths.c:277\r\n#8  0x00000000006eefbb in make_one_rel (root=0x1767c80, joinlist=0x17685b8) at allpaths.c:164\r\n#9  0x0000000000716573 in query_planner (root=0x1767c80, tlist=0x1767f70, qp_callback=0x71befa <standard_qp_callback>, qp_extra=0x7fffe7fa4ec0) at planmain.c:236\r\n#10 0x0000000000718dad in grouping_planner (root=0x1767c80, tuple_fraction=0) at planner.c:1535\r\n#11 0x000000000071742d in subquery_planner (glob=0x1767be8, parse=0x171adf8, parent_root=0x0, hasRecursion=0 '\\000', tuple_fraction=0, subroot=0x7fffe7fa5258)\r\n    at planner.c:612\r\n#12 0x0000000000716824 in standard_planner (parse=0x171adf8, cursorOptions=0, boundParams=0x0) at planner.c:229\r\n#13 0x00007f8d5318ea97 in pgstrom_planner_entrypoint (parse=0x171adf8, cursorOptions=0, boundParams=0x0) at src/main.c:317\r\n#14 0x0000000000716665 in planner (parse=0x171adf8, cursorOptions=0, boundParams=0x0) at planner.c:155\r\n#15 0x00000000007d4433 in pg_plan_query (querytree=0x171adf8, cursorOptions=0, boundParams=0x0) at postgres.c:809\r\n#16 0x00000000005f48de in ExplainOneQuery (query=0x171adf8, into=0x0, es=0x171ad28, queryString=0x170b728 \"explain select c1 from t1 where c1 < now();\", \r\n    params=0x0) at explain.c:351\r\n#17 0x00000000005f4604 in ExplainQuery (stmt=0x170c7c8, queryString=0x170b728 \"explain select c1 from t1 where c1 < now();\", params=0x0, dest=0x171ac90)\r\n    at explain.c:245\r\n#18 0x00000000007dc6bc in standard_ProcessUtility (parsetree=0x170c7c8, queryString=0x170b728 \"explain select c1 from t1 where c1 < now();\", \r\n    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, dest=0x171ac90, completionTag=0x7fffe7fa5670 \"\") at utility.c:658\r\n#19 0x00000000007dbeda in ProcessUtility (parsetree=0x170c7c8, queryString=0x170b728 \"explain select c1 from t1 where c1 < now();\", \r\n    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, dest=0x171ac90, completionTag=0x7fffe7fa5670 \"\") at utility.c:334\r\n#20 0x00000000007daf69 in PortalRunUtility (portal=0x16affe8, utilityStmt=0x170c7c8, isTopLevel=1 '\\001', dest=0x171ac90, completionTag=0x7fffe7fa5670 \"\")\r\n    at pquery.c:1187\r\n#21 0x00000000007dacce in FillPortalStore (portal=0x16affe8, isTopLevel=1 '\\001') at pquery.c:1061\r\n#22 0x00000000007da5f5 in PortalRun (portal=0x16affe8, count=9223372036854775807, isTopLevel=1 '\\001', dest=0x170d338, altdest=0x170d338, \r\n    completionTag=0x7fffe7fa5860 \"\") at pquery.c:785\r\n#23 0x00000000007d48e7 in exec_simple_query (query_string=0x170b728 \"explain select c1 from t1 where c1 < now();\") at postgres.c:1104\r\n#24 0x00000000007d8915 in PostgresMain (argc=1, argv=0x1696ce0, dbname=0x1696be0 \"nanzai\", username=0x1696bc0 \"nanzai\") at postgres.c:4025\r\n#25 0x000000000075b556 in BackendRun (port=0x16bed50) at postmaster.c:4230\r\n#26 0x000000000075acc9 in BackendStartup (port=0x16bed50) at postmaster.c:3906\r\n#27 0x00000000007574a2 in ServerLoop () at postmaster.c:1665\r\n#28 0x0000000000756ae9 in PostmasterMain (argc=1, argv=0x1695b80) at postmaster.c:1274\r\n#29 0x00000000006b0f32 in main (argc=1, argv=0x1695b80) at main.c:223\r\n```\r\n\r\nnow()にだけ対応するなら以下のパッチで動作することを確認していますが、\r\nPostgreSQLには他にもstatement_timestamp()、timeofday()、clock_timestamp()があります。\r\n\r\n```\r\ndiff --git a/src/codegen.c b/src/codegen.c\r\nindex 4fad84d..5562f24 100644\r\n--- a/src/codegen.c\r\n+++ b/src/codegen.c\r\n@@ -716,6 +716,9 @@ static devfunc_catalog_t devfunc_common_catalog[] = {\r\n                                          TIMESTAMPTZOID, TIMESTAMPTZOID},\r\n          \"t/F:overlaps_timestamptz\" },\r\n \r\n+       /* current time function */\r\n+       { \"now\", 0, {}, \"t/F:now\"},\r\n+\r\n        /*\r\n         * Text functions\r\n         * ---------------------- */\r\ndiff --git a/src/cuda_timelib.h b/src/cuda_timelib.h\r\nindex 5f7e2cb..7b9e0c6 100644\r\n--- a/src/cuda_timelib.h\r\n+++ b/src/cuda_timelib.h\r\n@@ -2988,6 +2988,19 @@ pgfn_interval_cmp(kern_context *kcxt, pg_interval_t arg1, pg_interval_t arg2)\r\n }\r\n \r\n /*\r\n+ * current date time function\r\n+ */\r\n+STATIC_FUNCTION(pg_timestamptz_t)\r\n+pgfn_now(kern_context *kcxt)\r\n+{\r\n+       pg_timestamptz_t result;\r\n+       kern_parambuf *kparams = kcxt->kparams;\r\n+       result.value  = kparams->xactStartTimestamp;\r\n+       result.isnull = false;\r\n+       return result;\r\n+}\r\n+\r\n+/*\r\n  * overlaps() SQL functions\r\n  *\r\n  * NOTE: Even though overlaps() has more variations, inline_function()\r\n```\r\n"}}