Changeset: f27dfe585138 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f27dfe585138 Added Files: sql/test/Tests/hot_snapshot.py sql/test/Tests/hot_snapshot.stable.err sql/test/Tests/hot_snapshot.stable.out sql/test/Tests/hot_snapshot_bz2.py sql/test/Tests/hot_snapshot_bz2.stable.err sql/test/Tests/hot_snapshot_bz2.stable.out sql/test/Tests/hot_snapshot_gz.py sql/test/Tests/hot_snapshot_gz.stable.err sql/test/Tests/hot_snapshot_gz.stable.out sql/test/Tests/hot_snapshot_lz4.py sql/test/Tests/hot_snapshot_lz4.stable.err sql/test/Tests/hot_snapshot_lz4.stable.out sql/test/Tests/hot_snapshot_xz.py sql/test/Tests/hot_snapshot_xz.stable.err sql/test/Tests/hot_snapshot_xz.stable.out Removed Files: sql/test/Tests/hot-snapshot-bz2.py sql/test/Tests/hot-snapshot-bz2.stable.err sql/test/Tests/hot-snapshot-bz2.stable.out sql/test/Tests/hot-snapshot-gz.py sql/test/Tests/hot-snapshot-gz.stable.err sql/test/Tests/hot-snapshot-gz.stable.out sql/test/Tests/hot-snapshot-lz4.py sql/test/Tests/hot-snapshot-lz4.stable.err sql/test/Tests/hot-snapshot-lz4.stable.out sql/test/Tests/hot-snapshot-xz.py sql/test/Tests/hot-snapshot-xz.stable.err sql/test/Tests/hot-snapshot-xz.stable.out sql/test/Tests/hot-snapshot.py sql/test/Tests/hot-snapshot.stable.err sql/test/Tests/hot-snapshot.stable.out sql/test/Tests/hot_snapshot_compression.py Modified Files: common/stream/stream.c monetdb5/modules/mal/pcre.c sql/backends/monet5/sql_subquery.c sql/server/rel_optimizer.c sql/server/rel_select.c sql/server/rel_unnest.c sql/server/rel_unnest.h sql/server/sql_query.c sql/server/sql_query.h sql/storage/bat/bat_logger.c sql/storage/store.c sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.stable.out sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.stable.out.int128 sql/test/BugTracker-2013/Tests/syntaxerror.Bug-3399.stable.out sql/test/Tests/All sql/test/bugs/Tests/select_select_bug.stable.out sql/test/subquery/Tests/correlated.stable.out sql/test/subquery/Tests/subquery.stable.out sql/test/subquery/Tests/subquery3.stable.err sql/test/subquery/Tests/subquery3.stable.out sql/test/subquery/Tests/subquery4.stable.out sql/test/subquery/Tests/subquery5.stable.out sql/test/subquery/Tests/subquery6.sql sql/test/subquery/Tests/subquery6.stable.err sql/test/subquery/Tests/subquery6.stable.out Branch: default Log Message:
Merged with Jun2020 diffs (truncated from 1953 to 300 lines): diff --git a/common/stream/stream.c b/common/stream/stream.c --- a/common/stream/stream.c +++ b/common/stream/stream.c @@ -1824,8 +1824,15 @@ stream_lz4close(stream *s) lz4_stream *lz4 = s->stream_data.p; if (lz4) { - stream_lz4flush(s); if(!s->readonly) { + char final_bytes[128]; // 4 would probably suffice + stream_lz4flush(s); + size_t remainder = LZ4F_compressEnd(lz4->context.comp_context, final_bytes, sizeof(final_bytes), NULL); + // no channel to return an error from here :( + if (!LZ4F_isError(remainder)) { + // again, hope for the best + (void) fwrite(final_bytes, 1, remainder, lz4->fp); + } (void) LZ4F_freeCompressionContext(lz4->context.comp_context); } else { (void) LZ4F_freeDecompressionContext(lz4->context.dec_context); diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c --- a/monetdb5/modules/mal/pcre.c +++ b/monetdb5/modules/mal/pcre.c @@ -233,7 +233,7 @@ myucslen(const uint32_t *ucs) return i; } -static int +static inline int mywstrncasecmp(const char *restrict s1, const uint32_t *restrict s2, size_t n2) { uint32_t c1; @@ -261,7 +261,7 @@ mywstrncasecmp(const char *restrict s1, return 0; } -static int +static inline int mystrcasecmp(const char *s1, const char *s2) { uint32_t c1, c2; @@ -289,7 +289,7 @@ mystrcasecmp(const char *s1, const char } } -static int +static inline int mywstrcasecmp(const char *restrict s1, const uint32_t *restrict s2) { uint32_t c1; @@ -315,7 +315,7 @@ mywstrcasecmp(const char *restrict s1, c } } -static const char * +static inline const char * mywstrcasestr(const char *restrict haystack, const uint32_t *restrict wneedle) { size_t nlen = myucslen(wneedle); @@ -394,7 +394,7 @@ is_strcmpable(const char *pat, const cha return strlen(esc) == 0 || strNil(esc) || strstr(pat, esc) == NULL; } -static bool +static inline bool re_match_ignore(const char *s, RE *pattern) { RE *r; @@ -410,7 +410,7 @@ re_match_ignore(const char *s, RE *patte return true; } -static bool +static inline bool re_match_no_ignore(const char *s, RE *pattern) { RE *r; @@ -725,8 +725,11 @@ re_likeselect(BAT **bnp, BAT *b, BAT *s, if (!use_strcmp) { re = re_create(pat, caseignore, esc); - if (!re) + if (!re) { + BBPreclaim(bn); + *bnp = NULL; throw(MAL, "pcre.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } } if (s && !BATtdense(s)) { struct canditer ci; @@ -737,8 +740,11 @@ re_likeselect(BAT **bnp, BAT *b, BAT *s, if (use_strcmp) { if (caseignore) { wpat = utf8stoucs(pat); - if (wpat == NULL) + if (wpat == NULL) { + BBPreclaim(bn); + *bnp = NULL; throw(MAL, "pcre.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } if (anti) candscanloop(v && *v != '\200' && mywstrcasecmp(v, wpat) != 0); @@ -788,8 +794,11 @@ re_likeselect(BAT **bnp, BAT *b, BAT *s, if (use_strcmp) { if (caseignore) { wpat = utf8stoucs(pat); - if (wpat == NULL) + if (wpat == NULL) { + BBPreclaim(bn); + *bnp = NULL; throw(MAL, "pcre.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } if (anti) scanloop(v && *v != '\200' && mywstrcasecmp(v, wpat) != 0); @@ -841,6 +850,103 @@ re_likeselect(BAT **bnp, BAT *b, BAT *s, throw(MAL, "pcre.likeselect", OPERATION_FAILED); } +#define proj_scanloop(TEST) \ + do { \ + if (b->tnonil) { \ + for (BUN p = 0; p < q; p++) { \ + v = BUNtail(bi, p); \ + res[p] = TEST; \ + } \ + } else { \ + for (BUN p = 0; p < q; p++) { \ + v = BUNtail(bi, p); \ + if (*v == '\200') { \ + res[p] = bit_nil; \ + bn->tnonil = false; \ + bn->tnil = true; \ + } else \ + res[p] = TEST; \ + } \ + } \ + } while (0) + +static str +re_like_proj(BAT **bnp, BAT *b, const char *pat, bool caseignore, bool anti, bool use_strcmp, uint32_t esc) +{ + BATiter bi = bat_iterator(b); + BAT *bn; + const char *restrict v; + RE *re = NULL; + uint32_t *wpat = NULL; + BUN q = BATcount(b); + bit *restrict res; + str msg = MAL_SUCCEED; + + assert(ATOMstorage(b->ttype) == TYPE_str); + + bn = COLnew(0, TYPE_bit, BATcount(b), TRANSIENT); + if (bn == NULL) { + msg = createException(MAL, "pcre.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL); + goto bailout; + } + res = (bit*) Tloc(bn, 0); + + if (!use_strcmp) { + re = re_create(pat, caseignore, esc); + if (!re) { + msg = createException(MAL, "pcre.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL); + goto bailout; + } + } + + if (use_strcmp) { + if (caseignore) { + wpat = utf8stoucs(pat); + if (wpat == NULL) { + msg = createException(MAL, "pcre.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL); + goto bailout; + } + if (anti) + proj_scanloop(mywstrcasecmp(v, wpat) != 0); + else + proj_scanloop(mywstrcasecmp(v, wpat) == 0); + } else { + if (anti) + proj_scanloop(strcmp(v, pat) != 0); + else + proj_scanloop(strcmp(v, pat) == 0); + } + } else { + if (caseignore) { + if (anti) + proj_scanloop(re_match_ignore(v, re) == 0); + else + proj_scanloop(re_match_ignore(v, re)); + } else { + if (anti) + proj_scanloop(re_match_no_ignore(v, re) == 0); + else + proj_scanloop(re_match_no_ignore(v, re)); + } + } + +bailout: + if (bn) { + if (msg) { + BBPreclaim(bn); + } else { + BATsetcount(bn, BATcount(b)); + bn->tsorted = false; + bn->trevsorted = false; + *bnp = bn; + } + } + if (re) + re_destroy(re); + GDKfree(wpat); + return msg; +} + /* maximum number of back references and quoted \ or $ in replacement string */ #define MAX_NR_REFS 20 @@ -1609,7 +1715,7 @@ PCRElike4(bit *ret, const str *s, const if (!r) { assert(ppat); - if (strNil(*pat) || strNil(*s)) { + if (strNil(*pat) || strNil(*s) || strNil(*esc)) { *ret = bit_nil; } else if (strNil(ppat)) { *ret = FALSE; @@ -1709,138 +1815,238 @@ PCREnotilike2(bit *ret, const str *s, co return MAL_SUCCEED; } +/* try if a simple list of keywords works */ +static str +choose_like_path(char **ppat, bool *use_re, bool *use_strcmp, bool *empty, const str *pat, const str *esc, const bit *caseignore) +{ + *use_re = false; + *use_strcmp = false; + *empty = false; + + if (strNil(*pat) || strNil(*esc)) { + *empty = true; + } else if (is_strcmpable(*pat, *esc)) { + *use_re = true; + *use_strcmp = true; + } else if (re_simple(*pat, (unsigned char) **esc)) { + *use_re = true; + } else { + str res = sql2pcre(ppat, *pat, *esc); + if (res != MAL_SUCCEED) + return res; + if (strNil(*ppat)) { + GDKfree(*ppat); + *ppat = NULL; + if (*caseignore) { + if (!(*ppat = GDKmalloc(strlen(*pat) + 3))) + throw(MAL, "algebra.likeselect", SQLSTATE(HY013) MAL_MALLOC_FAIL); + stpcpy(stpcpy(stpcpy(*ppat, "^"), *pat), "$"); + } + } + } + return MAL_SUCCEED; +} + +#define PCRE_LIKE_BODY(LOOP_BODY, RES1, RES2) \ + do { \ + if (b->tnonil) { \ + for (BUN p = 0; p < q; p++) { \ + const char *restrict s = BUNtail(bi, p); \ + LOOP_BODY \ + if (pos >= 0) \ + res[p] = RES1; \ + else if (pos == -1) \ + res[p] = RES2; \ + else { \ + msg = createException(MAL, "pcre.match", OPERATION_FAILED ": matching of regular expression (%s) failed with %d", ppat, pos); \ + goto bailout; \ + } \ + } \ + } else { \ + for (BUN p = 0; p < q; p++) { \ + const char *restrict s = BUNtail(bi, p); \ + LOOP_BODY \ + if (*s == '\200') { \ + res[p] = bit_nil; \ + bn->tnonil = false; \ + bn->tnil = true; \ + } else { \ + if (pos >= 0) \ + res[p] = RES1; \ + else if (pos == -1) \ + res[p] = RES2; \ + else { \ + msg = createException(MAL, "pcre.match", OPERATION_FAILED ": matching of regular expression (%s) failed with %d", ppat, pos); \ + goto bailout; \ + } \ + } \ + } \ + } \ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list