Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
30d48ac
finish part of parser; need to add handler function in create_executo…
Kangyan-Zhou Mar 22, 2018
086b493
finish part of parser; need to add handler function in create_executo…
Kangyan-Zhou Mar 22, 2018
59b85f6
Merge branch 'master' of https://github.com/HenryZhou0333/peloton
Kangyan-Zhou Mar 22, 2018
282afb3
Merge remote-tracking branch 'upstream/master'
Kangyan-Zhou Mar 27, 2018
28b702e
add postgresql parser test for sequences
Kangyan-Zhou Mar 28, 2018
ddb3dd7
remove AS in sequencce
Kangyan-Zhou Mar 28, 2018
26230e3
add exception for redefined parser
Kangyan-Zhou Mar 28, 2018
b273056
finish compiling create sequence
Kangyan-Zhou Mar 31, 2018
d90a649
Merge remote-tracking branch 'upstream/master'
Kangyan-Zhou Mar 31, 2018
c1a4e1d
having issue with GetSequence()
Kangyan-Zhou Apr 2, 2018
f8ec42a
add new GetSequence impl; fix BasicTest in sequence
Kangyan-Zhou Apr 8, 2018
0d3521c
add tests for sequence
Kangyan-Zhou Apr 10, 2018
8fe7d6c
fix merge conflict
Kangyan-Zhou Apr 10, 2018
87680be
one step before submitting pr
Kangyan-Zhou Apr 12, 2018
7d7955c
change way of update pg_sequence table in nextval
Kangyan-Zhou Apr 12, 2018
503c89f
style fix
Apr 12, 2018
7762354
rename sequence test
Kangyan-Zhou Apr 12, 2018
b340c86
Merge remote-tracking branch 'upstream/master'
Kangyan-Zhou Apr 12, 2018
6897566
remove unnecessary file
Kangyan-Zhou Apr 12, 2018
b8c7317
adding nextval & currval functions; comment out lock and nextval not …
danae-s Apr 14, 2018
d665c94
update pg_sequence after calling nextval; have seg fault in txn;
Kangyan-Zhou Apr 16, 2018
e71a21c
temporary add code from other team
Kangyan-Zhou Apr 23, 2018
ca8f8fe
fix conflict with master
Kangyan-Zhou May 4, 2018
85af574
again fix conflicts
Kangyan-Zhou May 4, 2018
7997a9a
move sequence catalog into system catalogs
Kangyan-Zhou May 4, 2018
35d6a5a
fix issues in comments; add sanity check for sequence arguments
Kangyan-Zhou May 4, 2018
6b12584
move sequence functions from string files to new files
Kangyan-Zhou May 5, 2018
bd4210e
implement nextval&currval for multi-session, minor bugs
danae-s May 5, 2018
80ad516
partially implemented drop seq
bdengNE May 5, 2018
e6811f9
merge
danae-s May 5, 2018
9106ba8
Merge branch 'pr2' of https://github.com/HenryZhou0333/peloton into pr2
danae-s May 5, 2018
28045be
fix bug with nextval & currval. now support multi-session
danae-s May 5, 2018
3d93dc6
fix bug with nextval & currval. now support multi-session
danae-s May 5, 2018
fc4a385
fixing some comments
Kangyan-Zhou May 5, 2018
527bfc5
add an exception case for currval
danae-s May 5, 2018
836ffc0
drop seq with errors
bdengNE May 5, 2018
5c760c6
drop seq with a bug about txn visibility
bdengNE May 6, 2018
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
16 changes: 16 additions & 0 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "function/date_functions.h"
#include "function/decimal_functions.h"
#include "function/old_engine_string_functions.h"
#include "function/string_functions.h"
#include "function/sequence_functions.h"
#include "function/timestamp_functions.h"
#include "index/index_factory.h"
#include "settings/settings_manager.h"
Expand Down Expand Up @@ -1204,6 +1206,20 @@ void Catalog::InitializeFunctions() {
function::BuiltInFuncType{OperatorId::Like,
function::OldEngineStringFunctions::Like},
txn);
// Sequence
AddBuiltinFunction(
"nextval", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "Nextval",
function::BuiltInFuncType{OperatorId::Nextval,
function::SequenceFunctions::_Nextval},
txn);
AddBuiltinFunction(
"currval", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "Currval",
function::BuiltInFuncType{OperatorId::Currval,
function::SequenceFunctions::_Currval},
txn);


/**
* decimal functions
Expand Down
73 changes: 73 additions & 0 deletions src/catalog/catalog_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include <memory>

#include "catalog/catalog_cache.h"
#include <boost/functional/hash.hpp>

#include "catalog/database_catalog.h"
#include "catalog/sequence_catalog.h"
#include "common/logger.h"

namespace peloton {
Expand Down Expand Up @@ -157,5 +159,76 @@ std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
return nullptr;
}

/*@brief insert sequence catalog object into cache
* @param sequence_object
* @return false only if sequence already exists in cache
*/
bool CatalogCache::InsertSequenceObject(
std::shared_ptr<SequenceCatalogObject> sequence_object) {
if (!sequence_object || sequence_object->seq_oid == INVALID_OID) {
return false; // invalid object

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, false doesn't indicate the sequence exists in the cache. Probably need to change the @return spec or requires the sequence_object to be valid.

}

std::size_t hash_key = GetHashKey(sequence_object->seq_name,
sequence_object->db_oid);

// check if already in cache
if (sequence_objects_cache.find(hash_key) !=
sequence_objects_cache.end()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to throw an exception for this case?

LOG_DEBUG("Sequence %s already exists in cache!",
sequence_object->seq_name.c_str());
return false;
}

sequence_objects_cache.insert(
std::make_pair(hash_key, sequence_object));
return true;
}

/*@brief evict sequence catalog object from cache
* @param sequence_name, database_oid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each parameter should be put on a separate line.

* @return true if specified sequence is found and evicted;
* false if not found
*/
bool CatalogCache::EvictSequenceObject(const std::string & sequence_name,
oid_t database_oid) {
std::size_t hash_key = GetHashKey(sequence_name, database_oid);

auto it = sequence_objects_cache.find(hash_key);
if (it == sequence_objects_cache.end()) {
return false; // sequence not found in cache
}

auto sequence_object = it->second;
PELOTON_ASSERT(sequence_object);
sequence_objects_cache.erase(it);
return true;
}

/*@brief get sequence catalog object from cache
* @param sequence_name, database_oid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each parameter should be put on a separate line.

* @return sequence catalog object; if not found return object with invalid oid
*/
std::shared_ptr<SequenceCatalogObject> CatalogCache::GetSequenceObject(
const std::string & sequence_name, oid_t database_oid) {
std::size_t hash_key = GetHashKey(sequence_name, database_oid);
auto it = sequence_objects_cache.find(hash_key);
if (it == sequence_objects_cache.end()) {
return nullptr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It said it return object with invalid oid if not found. To make things consistent, instead of returning nullptr, we should probably return an SequenceCatalogObject with seq_oid = INVALID_OID. Or another easier way is to change the spec.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a consistent behavior with the existing methods (like GetTableObejct, etc.) in catalog_cache.cpp so I would like to keep it.

}
return it->second;
}

/*@brief get the hash key given the sequence information
* @param sequence_name, database_oid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each parameter should be put on a separate line.

* @return hash key
*/
std::size_t CatalogCache::GetHashKey(const std::string sequence_name,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but wouldn't using reference, const std::string &, avoid unnecessary copies of strings?

oid_t database_oid) {
std::tuple<std::string, size_t> key(sequence_name, database_oid);
boost::hash<std::tuple<std::string, size_t>> key_hash;
return key_hash(key);
}

} // namespace catalog
} // namespace peloton
Loading