Changeset: 7349e79ea6ef for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7349e79ea6ef
Modified Files:
monetdb5/modules/atoms/mtime.c
Branch: Feb2013
Log Message:
Use column loop to speed up date extractions
The last step in improving the bulk operations on time components extractions.
The previous version relied on the expensive BUNappend calls. The new code
directly fills the arrays, making the instructions about 3x faster.
diffs (truncated from 857 to 300 lines):
diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -478,8 +478,6 @@ compute_rule(rule *val, int y)
return d;
}
-static int dummy;
-
#define BEFORE(d1,m1,d2,m2) (d1 < d2 || (d1 == d2 && m1 <= m2))
static int
@@ -489,6 +487,7 @@ timestamp_inside(timestamp *ret, timesta
lng add = (offset != (lng) 0) ? offset : (get_offset(z)) * (lng) 60000;
int start_days, start_msecs, end_days, end_msecs, year;
rule start, end;
+ int dummy;
MTIMEtimestamp_add(ret, t, &add);
@@ -1253,6 +1252,7 @@ timestamp_create(timestamp *ret, date *d
static str
date_extract_year(int *ret, date *v)
{
+ int dummy;
if (*v == date_nil) {
*ret = int_nil;
} else {
@@ -1265,6 +1265,7 @@ date_extract_year(int *ret, date *v)
static str
date_extract_month(int *ret, date *v)
{
+ int dummy;
if (*v == date_nil) {
*ret = int_nil;
} else {
@@ -1277,6 +1278,7 @@ date_extract_month(int *ret, date *v)
static str
date_extract_day(int *ret, date *v)
{
+ int dummy;
if (*v == date_nil) {
*ret = int_nil;
} else {
@@ -1289,6 +1291,7 @@ date_extract_day(int *ret, date *v)
static str
date_extract_dayofyear(int *ret, date *v)
{
+ int dummy;
if (*v == date_nil) {
*ret = int_nil;
} else {
@@ -1342,6 +1345,7 @@ date_extract_dayofweek(int *ret, date *v
static str
daytime_extract_hours(int *ret, daytime *v)
{
+ int dummy;
if (*v == daytime_nil) {
*ret = int_nil;
} else {
@@ -1354,6 +1358,7 @@ daytime_extract_hours(int *ret, daytime
static str
daytime_extract_minutes(int *ret, daytime *v)
{
+ int dummy;
if (*v == daytime_nil) {
*ret = int_nil;
} else {
@@ -1366,6 +1371,7 @@ daytime_extract_minutes(int *ret, daytim
static str
daytime_extract_seconds(int *ret, daytime *v)
{
+ int dummy;
if (*v == daytime_nil) {
*ret = int_nil;
} else {
@@ -1379,6 +1385,8 @@ static str
daytime_extract_sql_seconds(int *ret, daytime *v)
{
int sec, milli;
+ int dummy;
+
if (*v == daytime_nil) {
*ret = int_nil;
} else {
@@ -1392,6 +1400,7 @@ daytime_extract_sql_seconds(int *ret, da
static str
daytime_extract_milliseconds(int *ret, daytime *v)
{
+ int dummy;
if (*v == daytime_nil) {
*ret = int_nil;
} else {
@@ -2854,43 +2863,330 @@ str
MTIMEdate_extract_year_bulk(int *ret, int *bid)
{
BAT *b, *bn;
- int v;
- date d;
- BUN p, q;
- BATiter bi;
+ BUN i,n;
+ int *y;
+ date *t;
if ((b = BATdescriptor(*bid)) == NULL)
- throw(MAL, "bbp.getdate", "Cannot access descriptor");
+ throw(MAL, "batmtime.year", "Cannot access descriptor");
+ n = BATcount(b);
bn = BATnew(TYPE_void, TYPE_int, BATcount(b));
- if (bn == NULL)
+ if (bn == NULL){
+ BBPreleaseref(b->batCacheid);
throw(MAL, "batmtime.year", "memory allocation failure");
+ }
BATseqbase(bn, b->H->seq);
-
- bi = bat_iterator(b);
- BATloop(b, p, q) {
- d = *(date *) BUNtail(bi, p);
- MTIMEdate_extract_year(&v, &d);
- if (BUNappend(bn, &v, FALSE) == NULL) {
- BBPunfix(bn->batCacheid);
- throw(MAL, "batmtime.year", "inserting value failed");
+ bn->T->nonil = 1;
+ bn->T->nil = 0;
+
+ t = (date *) Tloc(b, BUNfirst(b));
+ y = (int *) Tloc(bn, BUNfirst(bn));
+ for( i = 0; i < n ; i++){
+ if ( *t == date_nil){
+ *y = int_nil;
+ } else
+ date_extract_year(y, t);
+ if (*y == int_nil){
+ bn->T->nonil = 0;
+ bn->T->nil = 1;
}
+ y++; t++;
}
- if (b->htype != bn->htype) {
- BAT *r = VIEWcreate(b,bn);
-
- BBPreleaseref(bn->batCacheid);
- bn = r;
- }
+ if (b->htype != bn->htype) {
+ BAT *r = VIEWcreate(b,bn);
+ BBPreleaseref(bn->batCacheid);
+ bn = r;
+ }
+
+ BATsetcount(bn, (BUN) (y - (int *) Tloc(bn, BUNfirst(bn))));
+ BATsettrivprop(bn);
bn->H->nonil = b->H->nonil;
+ bn->H->nil = b->H->nil;
+ bn->hsorted = b->hsorted;
+ bn->hrevsorted = b->hrevsorted;
+ BATkey(bn, BAThkey(b));
+
+ bn->tsorted = BATcount(bn)<2;
+ bn->trevsorted = BATcount(bn)<2;
+
+ BBPkeepref(*ret = bn->batCacheid);
+ BBPunfix(b->batCacheid);
+ return MAL_SUCCEED;
+}
+
+str
+MTIMEdate_extract_month_bulk(int *ret, int *bid)
+{
+ BAT *b, *bn;
+ BUN i,n;
+ int *m;
+ date *t;
+
+ if ((b = BATdescriptor(*bid)) == NULL)
+ throw(MAL, "batmtime.year", "Cannot access descriptor");
+ n = BATcount(b);
+
+ bn = BATnew(TYPE_void, TYPE_int, BATcount(b));
+ if (bn == NULL){
+ BBPreleaseref(b->batCacheid);
+ throw(MAL, "batmtime.month", "memory allocation failure");
+ }
+ BATseqbase(bn, b->H->seq);
+ bn->T->nonil = 1;
+ bn->T->nil = 0;
+
+ t = (date *) Tloc(b, BUNfirst(b));
+ m = (int *) Tloc(bn, BUNfirst(bn));
+ for( i = 0; i < n ; i++){
+ if ( *t == date_nil){
+ *m = int_nil;
+ } else
+ date_extract_month(m, t);
+ if (*m == int_nil){
+ bn->T->nonil = 0;
+ bn->T->nil = 1;
+ }
+ m++; t++;
+ }
+ if (b->htype != bn->htype) {
+ BAT *r = VIEWcreate(b,bn);
+ BBPreleaseref(bn->batCacheid);
+ bn = r;
+ }
+ BATsetcount(bn, (BUN) (m - (int *) Tloc(bn, BUNfirst(bn))));
+ BATsettrivprop(bn);
+
+ bn->H->nonil = b->H->nonil;
+ bn->H->nil = b->H->nil;
+ bn->hsorted = b->hsorted;
+ bn->hrevsorted = b->hrevsorted;
+ BATkey(bn, BAThkey(b));
+
+ bn->tsorted = BATcount(bn) < 2;
+ bn->trevsorted = BATcount(bn) < 2;
+
+ BBPkeepref(*ret = bn->batCacheid);
+ BBPunfix(b->batCacheid);
+ return MAL_SUCCEED;
+}
+
+str
+MTIMEdate_extract_day_bulk(int *ret, int *bid)
+{
+ BAT *b, *bn;
+ BUN i,n;
+ int *d;
+ date *t;
+
+ if ((b = BATdescriptor(*bid)) == NULL)
+ throw(MAL, "batmtime.day", "Cannot access descriptor");
+ n = BATcount(b);
+
+ bn = BATnew(TYPE_void, TYPE_int, BATcount(b));
+ if (bn == NULL){
+ BBPreleaseref(b->batCacheid);
+ throw(MAL, "batmtime.day", "memory allocation failure");
+ }
+ BATseqbase(bn, b->H->seq);
+ bn->T->nonil = 1;
+ bn->T->nil = 0;
+
+ t = (date *) Tloc(b, BUNfirst(b));
+ d = (int *) Tloc(bn, BUNfirst(bn));
+ for( i = 0; i < n ; i++){
+ if ( *t == date_nil){
+ *d = int_nil;
+ } else
+ date_extract_day(d, t);
+ if (*d == int_nil){
+ bn->T->nonil = 0;
+ bn->T->nil = 1;
+ }
+ d++; t++;
+ }
+
+ if (b->htype != bn->htype) {
+ BAT *r = VIEWcreate(b,bn);
+ BBPreleaseref(bn->batCacheid);
+ bn = r;
+ }
+ BATsetcount(bn, (BUN) (d - (int *) Tloc(bn, BUNfirst(bn))));
+ BATsettrivprop(bn);
+
+ bn->H->nonil = b->H->nonil;
+ bn->H->nil = b->H->nil;
+ bn->hsorted = b->hsorted;
+ bn->hrevsorted = b->hrevsorted;
+ BATkey(bn, BAThkey(b));
+
+ bn->tsorted = BATcount(bn) <2;
+ bn->trevsorted = BATcount(bn) <2;
+
+ BBPkeepref(*ret = bn->batCacheid);
+ BBPunfix(b->batCacheid);
+ return MAL_SUCCEED;
+}
+
+str
+MTIMEdaytime_extract_hours_bulk(int *ret, int *bid)
+{
+ BAT *b, *bn;
+ BUN i, n;
+ int *h;
+ date *t;
+
+ if ((b = BATdescriptor(*bid)) == NULL)
+ throw(MAL, "batmtime.hourse", "Cannot access descriptor");
+ n = BATcount(b);
+
+ bn = BATnew(TYPE_void, TYPE_int, BATcount(b));
+ if (bn == NULL){
+ BBPreleaseref(b->batCacheid);
+ throw(MAL, "batmtime.hours", "memory allocation failure");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list