-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement function DBMS_UTILITY.GET_TIME #135
Conversation
100th's of a second from a point in time in the past. This function is used for determining elapsed time. This function is widely used in some Oracle installation for timing of functions or statements. Example of use: DO $$ DECLARE start_time integer; end_time integer; BEGIN start_time := DBMS_UTILITY.GET_TIME; PERFORM pg_sleep(10); end_time := DBMS_UTILITY.GET_TIME; RAISE NOTICE 'Execution time: % seconds', (end_time - start_time)/100; END $$; This function do not return the same value as the Oracle implementation but it doesn't matter, it is used to get an elapsed time between two execution of the function.
Hi Pavel, more though this morning about this function. Let me know if it should be implemented in C, I have used SQL to be able to import the function without recompiling but I can keep it on my side and provide a probably faster C implementation. |
Hi. for simple things I prefer C implementation. Is question if it can be possible do this without lot of type conversions (there are four in one expression). |
Yes this is why I think a C implementation will be faster, ok will do. |
I hope so some like this code should to be enough gettimeofday(&tv, NULL); I believe so it does almost all, what your code. Probably it is not fully compatible with Oracle, because Oracle probably does PG_RETURN_INT32((int32) ((tv.tv_sec*1000000+tv.tv_usec)/(1000 * 10) + PG_INT32_MIN)); With last transformation, there are enough bits for interval 492 days, without it only for half days |
I have tried to understand how Oracle is calculating its value and the more approaching method I have found is the Here are the result of the different methods, the value returned by the function is the actual one, the other method are reported through NOTICE:
The second method looks acceptable for me even if the number of digit (10) doesn't correspond to the number of digit returned by the Oracle function (9). I'll push the fix. |
Maybe + PG_INT32_MIN is useless. Now it is positive, but next year, the number will be negative |
Right, so we fall back to your first solution that has negative value too. What I can propose it to take a far enough arbitrary time in the past to retrieved to epoch so that we will have a correct value. For example:
which gives
|
I have no strong opinion about it. This move to positive numbers now, but after 10 years the number will be negative again. Oracle allows negative numbers there - Numbers are returned in the range -2147483648 to 2147483647 depending on platform and machine, and your application must take the sign of the number into account in determining the interval. For instance, in the case of two negative numbers, application logic must allow that the first (earlier) number will be larger than the second (later) number which is closer to zero. By the same token, your application should also allow that the first (earlier) number be negative and the second (later) number be positive. I prefer to just cast from int64 to int32 only. It looks to most safe for me. |
A right the Oracle function can return negative value too, so yes the form |
pá 21. 5. 2021 v 13:57 odesílatel Gilles Darold ***@***.***>
napsal:
A right the Oracle function can return negative value too, so yes the form PG_RETURN_INT32((int32)
(tv.tv_sec*1000000+tv.tv_usec)/10000); can be used and as it is mainly
used to get an elapsed time normally there is no need to rewrite the
application. Do you want me to post a new PR to avoid pollution with all
this commit history?
yes, if it is possible
—
… You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#135 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEFO4YZKF73B5YSOWUVDZTTOZDBBANCNFSM45DH55JA>
.
|
No description provided.