Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/duckdb/src/function/scalar/operator/arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ hugeint_t InterpolateOperator::Operation(const hugeint_t &lo, const double d, co

template <>
uhugeint_t InterpolateOperator::Operation(const uhugeint_t &lo, const double d, const uhugeint_t &hi) {
return Hugeint::Convert(Operation(Uhugeint::Cast<double>(lo), d, Uhugeint::Cast<double>(hi)));
return Uhugeint::Convert(Operation(Uhugeint::Cast<double>(lo), d, Uhugeint::Cast<double>(hi)));
}

static interval_t MultiplyByDouble(const interval_t &i, const double &d) { // NOLINT
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "2-dev21"
#define DUCKDB_PATCH_VERSION "2-dev31"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 4
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.4.2-dev21"
#define DUCKDB_VERSION "v1.4.2-dev31"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "716e174217"
#define DUCKDB_SOURCE_ID "46beeea72f"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/include/duckdb/common/hugeint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct hugeint_t { // NOLINT: use numeric casing
DUCKDB_API explicit operator int16_t() const;
DUCKDB_API explicit operator int32_t() const;
DUCKDB_API explicit operator int64_t() const;
DUCKDB_API operator uhugeint_t() const; // NOLINT: Allow implicit conversion from `hugeint_t`
DUCKDB_API explicit operator uhugeint_t() const;
};

} // namespace duckdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,4 @@ inline bool GreaterThan::Operation(const interval_t &left, const interval_t &rig
return Interval::GreaterThan(left, right);
}

//===--------------------------------------------------------------------===//
// Specialized Hugeint Comparison Operators
//===--------------------------------------------------------------------===//
template <>
inline bool Equals::Operation(const hugeint_t &left, const hugeint_t &right) {
return Hugeint::Equals(left, right);
}
template <>
inline bool GreaterThan::Operation(const hugeint_t &left, const hugeint_t &right) {
return Hugeint::GreaterThan(left, right);
}
} // namespace duckdb
12 changes: 6 additions & 6 deletions src/duckdb/src/include/duckdb/common/types/hugeint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,38 +129,38 @@ class Hugeint {
static int Sign(hugeint_t n);
static hugeint_t Abs(hugeint_t n);
// comparison operators
static bool Equals(hugeint_t lhs, hugeint_t rhs) {
static bool Equals(const hugeint_t &lhs, const hugeint_t &rhs) {
bool lower_equals = lhs.lower == rhs.lower;
bool upper_equals = lhs.upper == rhs.upper;
return lower_equals && upper_equals;
}

static bool NotEquals(hugeint_t lhs, hugeint_t rhs) {
static bool NotEquals(const hugeint_t &lhs, const hugeint_t &rhs) {
return !Equals(lhs, rhs);
}

static bool GreaterThan(hugeint_t lhs, hugeint_t rhs) {
static bool GreaterThan(const hugeint_t &lhs, const hugeint_t &rhs) {
bool upper_bigger = lhs.upper > rhs.upper;
bool upper_equal = lhs.upper == rhs.upper;
bool lower_bigger = lhs.lower > rhs.lower;
return upper_bigger || (upper_equal && lower_bigger);
}

static bool GreaterThanEquals(hugeint_t lhs, hugeint_t rhs) {
static bool GreaterThanEquals(const hugeint_t &lhs, const hugeint_t &rhs) {
bool upper_bigger = lhs.upper > rhs.upper;
bool upper_equal = lhs.upper == rhs.upper;
bool lower_bigger_equals = lhs.lower >= rhs.lower;
return upper_bigger || (upper_equal && lower_bigger_equals);
}

static bool LessThan(hugeint_t lhs, hugeint_t rhs) {
static bool LessThan(const hugeint_t &lhs, const hugeint_t &rhs) {
bool upper_smaller = lhs.upper < rhs.upper;
bool upper_equal = lhs.upper == rhs.upper;
bool lower_smaller = lhs.lower < rhs.lower;
return upper_smaller || (upper_equal && lower_smaller);
}

static bool LessThanEquals(hugeint_t lhs, hugeint_t rhs) {
static bool LessThanEquals(const hugeint_t &lhs, const hugeint_t &rhs) {
bool upper_smaller = lhs.upper < rhs.upper;
bool upper_equal = lhs.upper == rhs.upper;
bool lower_smaller_equals = lhs.lower <= rhs.lower;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "duckdb/common/mutex.hpp"
#include "duckdb/common/case_insensitive_map.hpp"
#include "duckdb/common/enums/on_create_conflict.hpp"
#include "duckdb/common/enums/access_mode.hpp"

namespace duckdb {
struct AttachInfo;
Expand All @@ -20,11 +21,14 @@ struct AttachOptions;
enum class InsertDatabasePathResult { SUCCESS, ALREADY_EXISTS };

struct DatabasePathInfo {
explicit DatabasePathInfo(string name_p) : name(std::move(name_p)), is_attached(true) {
explicit DatabasePathInfo(string name_p, AccessMode access_mode)
: name(std::move(name_p)), access_mode(access_mode), is_attached(true) {
}

string name;
AccessMode access_mode;
bool is_attached;
idx_t reference_count = 1;
};

//! The DatabaseFilePathManager is used to ensure we only ever open a single database file once
Expand Down

This file was deleted.

36 changes: 25 additions & 11 deletions src/duckdb/src/main/database_file_path_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ InsertDatabasePathResult DatabaseFilePathManager::InsertDatabasePath(const strin
}

lock_guard<mutex> path_lock(db_paths_lock);
auto entry = db_paths.emplace(path, DatabasePathInfo(name));
auto entry = db_paths.emplace(path, DatabasePathInfo(name, options.access_mode));
if (!entry.second) {
auto &existing = entry.first->second;
if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT && existing.name == name) {
if (existing.is_attached) {
return InsertDatabasePathResult::ALREADY_EXISTS;
if (options.access_mode == AccessMode::READ_ONLY && existing.access_mode == AccessMode::READ_ONLY) {
// all attaches are in read-only mode - there is no conflict, just increase the reference count
existing.reference_count++;
} else {
if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT && existing.name == name) {
if (existing.is_attached) {
return InsertDatabasePathResult::ALREADY_EXISTS;
}
throw BinderException(
"Unique file handle conflict: Cannot attach \"%s\" - the database file \"%s\" is in "
"the process of being detached",
name, path);
}
throw BinderException("Unique file handle conflict: Cannot attach \"%s\" - the database file \"%s\" is in "
"the process of being detached",
name, path);
throw BinderException(
"Unique file handle conflict: Cannot attach \"%s\" - the database file \"%s\" is already "
"attached by database \"%s\"",
name, path, existing.name);
}
throw BinderException("Unique file handle conflict: Cannot attach \"%s\" - the database file \"%s\" is already "
"attached by database \"%s\"",
name, path, existing.name);
}
options.stored_database_path = make_uniq<StoredDatabasePath>(*this, path, name);
return InsertDatabasePathResult::SUCCESS;
Expand All @@ -42,7 +49,14 @@ void DatabaseFilePathManager::EraseDatabasePath(const string &path) {
return;
}
lock_guard<mutex> path_lock(db_paths_lock);
db_paths.erase(path);
auto entry = db_paths.find(path);
if (entry != db_paths.end()) {
if (entry->second.reference_count <= 1) {
db_paths.erase(entry);
} else {
entry->second.reference_count--;
}
}
}

void DatabaseFilePathManager::DetachDatabase(const string &path) {
Expand Down