[HACKERS] clock_timestamp() and transcation_timestamp() patch

2003-07-15 Thread Wang Mike
diff -u -r ../postgresql-snapshot/src/backend/utils/adt/nabstime.c 
../pgsql/src/backend/utils/adt/nabstime.c
--- ../postgresql-snapshot/src/backend/utils/adt/nabstime.c	2003-05-13 
07:08:50.0 +0800
+++ ../pgsql/src/backend/utils/adt/nabstime.c	2003-07-15 11:08:06.0 
+0800
@@ -76,7 +76,6 @@
 * Function prototypes -- internal to this file only
 */

-static AbsoluteTime tm2abstime(struct tm * tm, int tz);
static void reltime2tm(RelativeTime time, struct tm * tm);
static int istinterval(char *i_string,
			AbsoluteTime *i_start,
@@ -311,7 +310,7 @@
 * Convert a tm structure to abstime.
 * Note that tm has full year (not 1900-based) and 1-based month.
 */
-static AbsoluteTime
+AbsoluteTime
tm2abstime(struct tm * tm, int tz)
{
	int			day;
diff -u -r ../postgresql-snapshot/src/backend/utils/adt/timestamp.c 
../pgsql/src/backend/utils/adt/timestamp.c
--- ../postgresql-snapshot/src/backend/utils/adt/timestamp.c	2003-05-13 
07:08:50.0 +0800
+++ ../pgsql/src/backend/utils/adt/timestamp.c	2003-07-15 
20:42:39.0 +0800
@@ -847,7 +847,65 @@
	result = AbsoluteTimeUsecToTimestampTz(sec, usec);

PG_RETURN_TIMESTAMPTZ(result);
-}
+}  /* now() */
+
+/*
+ * Function transaction_timestamp() return current transaction timestamp.
+ * Added by Xiongjian Wang (MikeWang)
+*/
+Datum
+transaction_timestamp(PG_FUNCTION_ARGS)
+{
+   TimestampTz result;
+   AbsoluteTime sec;
+   int usec;
+
+   sec = GetCurrentTransactionStartTimeUsec(usec);
+
+   result = AbsoluteTimeUsecToTimestampTz(sec, usec);
+
+   PG_RETURN_TIMESTAMPTZ(result);
+}  /* transaction_timestamp() */
+
+/*
+ * Function clock_timestamp() return current clock timestamp.
+ * Added by Xiongjian Wang (MikeWang)
+*/
+Datum
+clock_timestamp(PG_FUNCTION_ARGS)
+{
+   TimestampTz result;
+   AbsoluteTime sec;
+   int usec;
+
+   sec = GetCurrentAbsoluteTimeUsec(usec);
+
+   result = AbsoluteTimeUsecToTimestampTz(sec, usec);
+
+   PG_RETURN_TIMESTAMPTZ(result);
+}  /* clock_timestamp() */
+
+Datum
+transaction_interval(PG_FUNCTION_ARGS)
+{
+   Timestamp trans_tz;
+   Timestamp clock_tz;
+   
+   AbsoluteTime trans_sec;
+   AbsoluteTime clock_sec;
+   int trans_usec;
+   int clock_usec;
+
+   clock_sec = GetCurrentAbsoluteTimeUsec(clock_usec);
+   trans_sec = GetCurrentTransactionStartTimeUsec(trans_usec);
+
+   trans_tz = AbsoluteTimeUsecToTimestampTz(trans_sec, trans_usec);
+   clock_tz = AbsoluteTimeUsecToTimestampTz(clock_sec, clock_usec);
+
+   return DirectFunctionCall2(timestamp_mi,
+  TimestampGetDatum(clock_tz),
+  
TimestampGetDatum(trans_tz));
+}  /* transaction_interval() */
void
dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
diff -u -r ../postgresql-snapshot/src/include/catalog/pg_proc.h 
../pgsql/src/include/catalog/pg_proc.h
--- ../postgresql-snapshot/src/include/catalog/pg_proc.h	2003-06-23 
06:04:55.0 +0800
+++ ../pgsql/src/include/catalog/pg_proc.h	2003-07-15 20:54:06.0 
+0800
@@ -3394,6 +3394,15 @@
DATA(insert OID = 2503 (  anyarray_send		   PGNSP PGUID 12 f f t f s 1 17 
2277  anyarray_send - _null_ ));
DESCR(I/O);

+/* Added by Xiongjian Wang (MikeWang) */
+DATA(insert OID = 5001 (  transaction_timestamp	PGNSP PGUID 12 f f t f s 0 
1184   transaction_timestamp - _null_ ));
+DESCR(current transaction timestamp like as function now());
+
+DATA(insert OID = 5002 (  clock_timestamp PGNSP PGUID 12 f f t f v 0 1184 
  clock_timestamp - _null_ ));
+DESCR(current clock timestamp);
+
+DATA(insert OID = 5003 (  transaction_interval PGNSP PGUID 12 f f t f v 0 
1186   transaction_interval - _null_ ));
+DESCR(current transaction runs into present interval);

/*
 * Symbolic values for provolatile column: these indicate whether the 
result
diff -u -r ../postgresql-snapshot/src/include/utils/nabstime.h 
../pgsql/src/include/utils/nabstime.h
--- ../postgresql-snapshot/src/include/utils/nabstime.h	2003-05-13 
07:08:52.0 +0800
+++ ../pgsql/src/include/utils/nabstime.h	2003-07-15 11:06:41.0 
+0800
@@ -165,5 +165,5 @@
extern AbsoluteTime GetCurrentAbsoluteTimeUsec(int *usec);
extern TimestampTz AbsoluteTimeUsecToTimestampTz(AbsoluteTime sec, int 
usec);
extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char 
**tzn);
-
+extern AbsoluteTime tm2abstime(struct tm * tm, int tz);
#endif   /* NABSTIME_H */
diff -u -r ../postgresql-snapshot/src/include/utils/timestamp.h 
../pgsql/src/include/utils/timestamp.h
--- ../postgresql-snapshot/src/include/utils/timestamp.h	2003-05-13 
07:08:52.0 +0800
+++ ../pgsql/src/include/utils/timestamp.h	2003-07-15 20:44:35.0 
+0800
@@ -233,20 +233,24 @@

extern Datum now(PG_FUNCTION_ARGS);

-/* Internal routines (not fmgr-callable) */
+/* Add by Xiongjian Wang (Mike Wang

[HACKERS] a problem with index and user define type

2003-06-21 Thread Wang Mike
Hi all:
  I write a use define type (UUID)
typedef struct uuid
{
uint32 time_low;
uint16 time_mid;
uint16 time_hi_and_version;
uint8 clock_seq_hi_and_reserved;
uint8 clock_seq_low;
uint8 node[6];
} uuid;
make all btree index function and operator, such as

CREATE OPERATOR CLASS uuid_btree_ops
DEFAULT FOR TYPE uuid USING btree 
AS
   OPERATOR1,
   OPERATOR2   = ,
   OPERATOR3   = ,
   OPERATOR4   = ,
   OPERATOR5,
   FUNCTION1   uuid_cmp(uuid, uuid),

create table test_uuid(id uuid primary key default uuid_time(), name 
char(40));

but  this query: select * from test_uuid where id = 
'df2b10aa-a31d-11d7-9867-0050babb6029'::uuid   dosn't use index

 QUERY PLAN
---
Seq Scan on test_uuid  (cost=0.00..22.50 rows=500 width=140)
  Filter: (id = 'df2b10aa-a31d-11d7-9867-0050babb6029'::uuid)
why ??

source code  see attachement 

  MikeWang

-
What is uuid?
   
   
   uuid is a kind of data type, provide for PostgreSQL to implement unique 
id in cyberspace,
   it's based one UUID URN name space IETF draft (see 
doc/draft-mealling-uuid-urn-00.txt),
   now, pguuid support NIL(0), Time-Base(1), Name-Base(3) and 
Random-Base(4) type UUID.
   It's propuse is
provide a solution
   for data replication, merge, and distribute.
   
   
what is the use of uuid?
   
   
   1, pguuid provide PostgreSQL a data type: uuid, it can provide unique 
id in
cyberspace.
   2, provide type uuid related operator (e.g. =, , , , =, =)
   3, provide functions to generate Time-base, Name-base, Random-base and 
Nil-UUID.
   4, provide functions to parse uuid type.

license:
   BSD
_
 MSN Messenger:  http://messenger.msn.com/cn  


uuid-v2.0.1.0.tar.gz
Description: GNU Zip compressed data

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly