// -------------------------------------------------------------------------------- // bool guDbCache::SetContent( const wxString &url, const wxString &content, const int type ) { wxString query = wxString::Format( wxT( "INSERT INTO cache( cache_id, cache_key, cache_data, " \ "cache_type, cache_time, cache_size ) VALUES( NULL, '%s', '%s', %u, %lu, %u );" ), escape_query_str( url ).c_str(), escape_query_str( content ).c_str(), type, wxDateTime::Now().GetTicks(), 0 ); ExecuteUpdate( query ); // delete the expired entries but call it only 2% of the times if( guRandom( 1000 ) < 7 ) ClearExpired(); return true; }
// -------------------------------------------------------------------------------- // guDbCache::guDbCache( const wxString &dbname ) : guDb( dbname ) { wxArrayString query; query.Add( wxT( "CREATE TABLE IF NOT EXISTS cache( cache_id INTEGER PRIMARY KEY AUTOINCREMENT, " \ "cache_key varchar, cache_data BLOB, cache_time INTEGER, " \ "cache_type INTEGER, cache_size INTEGER );" ) ); query.Add( wxT( "CREATE UNIQUE INDEX IF NOT EXISTS 'cache_id' on cache( cache_id ASC );" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'cache_key' on cache( cache_key ASC );" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'cache_time' on cache( cache_time ASC );" ) ); int Index; int Count = query.Count(); for( Index = 0; Index < Count; Index++ ) { //guLogMessage( query[ Index ] ); ExecuteUpdate( query[ Index ] ); } }
// -------------------------------------------------------------------------------- // void guDbRadios::SetRadioStation( const guRadioStation * radiostation ) { wxString query; if( radiostation->m_Id != wxNOT_FOUND ) { query = wxString::Format( wxT( "UPDATE radiostations SET " \ "radiostation_scid = %u, radiostation_source = %u, radiostation_genreid = %u, " \ "radiostation_name = '%s', radiostation_link = '%s', radiostation_type = '%s', " \ "radiostation_br = %u, radiostation_lc = %u, radiostation_ct = '%s' WHERE radiostation_id = %u;" ), radiostation->m_SCId, radiostation->m_Source, radiostation->m_GenreId, escape_query_str( radiostation->m_Name ).c_str(), escape_query_str( radiostation->m_Link ).c_str(), escape_query_str( radiostation->m_Type ).c_str(), radiostation->m_BitRate, radiostation->m_Listeners, escape_query_str( radiostation->m_NowPlaying ).c_str(), radiostation->m_Id ); } else { query = wxString::Format( wxT( "INSERT INTO radiostations( radiostation_id, radiostation_scid, radiostation_source, radiostation_genreid, " \ "radiostation_name, radiostation_link, radiostation_type, radiostation_br, radiostation_lc, radiostation_ct ) " \ "VALUES( NULL, %u, %u, %u, '%s', '%s', '%s', %u, %u, '%s' );" ), radiostation->m_SCId, radiostation->m_Source, radiostation->m_GenreId, escape_query_str( radiostation->m_Name ).c_str(), escape_query_str( radiostation->m_Link ).c_str(), escape_query_str( radiostation->m_Type ).c_str(), radiostation->m_BitRate, radiostation->m_Listeners, escape_query_str( radiostation->m_NowPlaying ).c_str() ); } //guLogMessage( wxT( "SetRadioStation:\n%s" ), query.c_str() ); ExecuteUpdate( query ); }
void FbConfigDatabase::DoUpgrade(int version) { switch (version) { case 2: { /** TABLE states **/ ExecuteUpdate(fbT("CREATE TABLE states(md5sum CHAR(32) PRIMARY KEY,rating INTEGER,download INTEGER)")); ExecuteUpdate(fbT("CREATE INDEX states_rating ON states(rating)")); } break; case 3: { /** TABLE script **/ ExecuteUpdate(fbT("CREATE TABLE script(id INTEGER PRIMARY KEY,name,text)")); } break; case 4: { /** TABLE script **/ ExecuteUpdate(fbT("UPDATE states SET download=-2-download WHERE download>0")); ExecuteUpdate(fbT("UPDATE states SET download=1 WHERE download=-2")); ExecuteUpdate(fbT("UPDATE states SET download=101 WHERE download=-1")); } break; } }
// -------------------------------------------------------------------------------- // int guDbRadios::DelRadioStation( const int radioid ) { wxString query; query = wxString::Format( wxT( "DELETE FROM radiostations WHERE radiostation_id = %u" ), radioid ); return ExecuteUpdate( query ); }
// -------------------------------------------------------------------------------- // guDbRadios::guDbRadios( const wxString &dbname ) : guDb( dbname ) { wxArrayString query; query.Add( wxT( "CREATE TABLE IF NOT EXISTS radiogenres( radiogenre_id INTEGER PRIMARY KEY AUTOINCREMENT, " \ "radiogenre_name VARCHAR COLLATE NOCASE, radiogenre_source INTEGER, radiogenre_flags INTEGER );" ) ); //query.Add( wxT( "CREATE UNIQUE INDEX IF NOT EXISTS 'radiogenre_id' on radiogenres (radiogenre_id ASC);" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 1, '60s', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 2, '80s', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 3, '90s', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 4, 'Alternative', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 5, 'Ambient', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 6, 'Blues', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 7, 'Chill', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 8, 'Classical', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 9, 'Country', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 10, 'Dance', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 11, 'Downtempo', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 12, 'Easy Listening', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 13, 'Electronic', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 14, 'Funk', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 15, 'Heavy Metal', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 16, 'House', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 17, 'Jazz', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 18, 'New Age', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 19, 'Oldies', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 20, 'Pop', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 21, 'Reggae', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 22, 'R&B/Urban', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 23, 'Rock', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 24, 'Smooth Jazz', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 25, 'Slow', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 26, 'Techno', 0, 0 );" ) ); query.Add( wxT( "INSERT OR IGNORE INTO radiogenres( radiogenre_id, radiogenre_name, radiogenre_source, radiogenre_flags ) VALUES( 27, 'Top 40', 0, 0 );" ) ); query.Add( wxT( "CREATE TABLE IF NOT EXISTS radiostations( radiostation_id INTEGER PRIMARY KEY AUTOINCREMENT, " \ "radiostation_scid INTEGER, radiostation_source INTEGER, radiostation_genreid INTEGER, " \ "radiostation_name VARCHAR COLLATE NOCASE, radiostation_link VARCHAR, radiostation_type VARCHAR, " \ "radiostation_br INTEGER, radiostation_lc INTEGER, radiostation_ct VARCHAR );" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'radiostation_scid' on radiostations (radiostation_scid ASC);" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'radiostation_genreid' on radiostations (radiostation_source,radiostation_genreid ASC);" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'radiostation_lc' on radiostations (radiostation_lc ASC);" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'radiostation_type' on radiostations (radiostation_type ASC);" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'radiostation_ct' on radiostations (radiostation_ct ASC);" ) ); query.Add( wxT( "CREATE TABLE IF NOT EXISTS radiolabels( radiolabel_id INTEGER PRIMARY KEY AUTOINCREMENT, radiolabel_name VARCHAR COLLATE NOCASE);" ) ); query.Add( wxT( "CREATE TABLE IF NOT EXISTS radiosetlabels( radiosetlabel_id INTEGER PRIMARY KEY AUTOINCREMENT, radiosetlabel_labelid INTEGER, radiosetlabel_stationid INTEGER);" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'radiosetlabel_labelid' on radiosetlabels (radiosetlabel_labelid ASC);" ) ); query.Add( wxT( "CREATE INDEX IF NOT EXISTS 'radiosetlabel_stationidid' on radiosetlabels (radiosetlabel_stationid ASC);" ) ); int Index; int Count = query.Count(); for( Index = 0; Index < Count; Index++ ) { ExecuteUpdate( query[ Index ] ); } guConfig * Config = ( guConfig * ) guConfig::Get(); if( Config ) { m_StationsOrder = Config->ReadNum( wxT( "StationsOrder" ), 0, wxT( "radios" ) ); m_StationsOrderDesc = Config->ReadBool( wxT( "StationsOrderDesc" ), false, wxT( "radios" ) ); } m_RadioSource = guRADIO_SOURCE_SHOUTCAST_GENRE; m_RaTeFilters.Empty(); m_RaGeFilters.Empty(); m_RaLaFilters.Empty(); }
void FbConfigDatabase::CreateDatabase() { FbSQLite3Transaction trans(this, WXSQLITE_TRANSACTION_IMMEDIATE); /** TABLE params **/ ExecuteUpdate(fbT("CREATE TABLE config(id INTEGER PRIMARY KEY,value INTEGER,text)")); ExecuteUpdate(fbT("INSERT INTO config(id,text)VALUES(1,'MyRuLib local config')")); ExecuteUpdate(fbT("INSERT INTO config(id,value)VALUES(2,1)")); /** TABLE types **/ ExecuteUpdate(fbT("CREATE TABLE types(file_type varchar(99) primary key,command,convert)")); /** TABLE comments **/ ExecuteUpdate(fbT("CREATE TABLE comments(id INTEGER PRIMARY KEY,md5sum CHAR(32),rating INTEGER,posted datetime,caption,comment)")); ExecuteUpdate(fbT("CREATE INDEX comments_book ON comments(md5sum)")); /** TABLE folders **/ ExecuteUpdate(fbT("CREATE TABLE folders(id INTEGER PRIMARY KEY,value)")); ExecuteUpdate(wxString::Format(wxT("INSERT INTO folders(id,value)VALUES(-1,'%s')"), _("The best"))); ExecuteUpdate(wxString::Format(wxT("INSERT INTO folders(id,value)VALUES(-2,'%s')"), _("Other"))); /** TABLE favorites **/ ExecuteUpdate(fbT("CREATE TABLE favorites(md5sum CHAR(32),id_folder INTEGER,PRIMARY KEY(md5sum,id_folder))")); ExecuteUpdate(fbT("CREATE INDEX favorites_folder ON favorites(id_folder)")); trans.Commit(); }
void FbMainDatabase::CreateDatabase() { FbSQLite3Transaction trans(this, WXSQLITE_TRANSACTION_IMMEDIATE); /** TABLE authors **/ ExecuteUpdate(fbT("CREATE TABLE authors(id INTEGER PRIMARY KEY,letter,search_name,full_name,first_name,middle_name,last_name,newid,description)")); ExecuteUpdate(fbT("INSERT INTO authors(id,letter,full_name)values(0,'#','(empty)')")); ExecuteUpdate(fbT("CREATE INDEX author_letter ON authors(letter)")); ExecuteUpdate(fbT("CREATE INDEX author_name ON authors(search_name)")); /** TABLE books **/ ExecuteUpdate(fbT("CREATE TABLE books(id INTEGER,id_author INTEGER,title,annotation,genres,deleted,id_archive,file_name,file_size,file_type,description,PRIMARY KEY(id,id_author))")); ExecuteUpdate(fbT("CREATE INDEX book_author ON books(id_author)")); ExecuteUpdate(fbT("CREATE INDEX book_archive ON books(id_archive)")); /** TABLE archives **/ ExecuteUpdate(fbT("CREATE TABLE archives(id INTEGER PRIMARY KEY,file_name,file_path,file_size,file_count)")); /** TABLE sequences **/ ExecuteUpdate(fbT("CREATE TABLE sequences(id INTEGER PRIMARY KEY,value)")); ExecuteUpdate(fbT("CREATE INDEX sequences_name ON sequences(value)")); /** TABLE bookseq **/ ExecuteUpdate(fbT("CREATE TABLE bookseq(id_book INTEGER, id_seq INTEGER,number INTEGER,level INTEGER,id_author INTEGER,PRIMARY KEY(id_book,id_seq))")); ExecuteUpdate(fbT("CREATE INDEX bookseq_seq ON bookseq(id_seq)")); /** TABLE params **/ ExecuteUpdate(fbT("CREATE TABLE params(id INTEGER PRIMARY KEY,value INTEGER,text)")); ExecuteUpdate(fbT("INSERT INTO params(id,text)VALUES (1,'My own Library')")); ExecuteUpdate(fbT("INSERT INTO params(id,value)VALUES (2,1)")); /** TABLE genres **/ ExecuteUpdate(fbT("CREATE TABLE genres(id_book integer,id_genre CHAR(2),PRIMARY KEY(id_book,id_genre))")); ExecuteUpdate(fbT("CREATE INDEX genres_genre ON genres(id_genre)")); trans.Commit(); CreateFullText(); }
void FbMasterDatabase::SetVersion(int iValue) { ExecuteUpdate(wxString::Format(wxT("INSERT OR REPLACE INTO %s(id,value)VALUES(2,%d)"), GetMaster().c_str(), iValue)); }
FbLocalDatabase::FbLocalDatabase() { FbDatabase::Open(GetConfigName()); ExecuteUpdate(fbT("PRAGMA temp_store=2")); SetCollation(wxT("CYR"), &sm_collation); }
int phddns_step(PHGlobal *phglobal) { int ret = 0; if (phglobal->bNeed_connect) { strcpy(phglobal->szActiveDomains[0],"."); phglobal->cLastResult = okConnecting; if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, 0); if (!InitializeSockets(phglobal)) { LOG(1) ("InitializeSockets failed, waiting for 5 seconds to retry...\n"); phglobal->cLastResult = errorConnectFailed; if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, 0); return 5; } ret = ExecuteUpdate(phglobal); phglobal->cLastResult = ret; if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, ret == okDomainsRegistered ? phglobal->nUserType : 0); if (ret == okDomainsRegistered) { //OnUserInfo(phglobal->szUserInfo); //OnAccountDomainInfo(phglobal->szDomainInfo); LOG(1) ("ExecuteUpdate OK, BeginKeepAlive!\n"); phglobal->bTcpUpdateSuccessed = TRUE; phglobal->tmLastResponse = time(0); phglobal->bNeed_connect = FALSE; BeginKeepAlive(phglobal); phglobal->lasttcptime = phglobal->tmLastSend = time(0); } else { if (ret == okRedirecting) { phglobal->bTcpUpdateSuccessed = FALSE; phglobal->bNeed_connect = TRUE; LOG(1) ("Need redirect, waiting for 5 seconds...\n"); return 5; } LOG(1) ("ExecuteUpdate failed, waiting for 30 seconds to retry...\n"); return 30; } phglobal->nLastResponseID = -1; } else { if (time(0) - phglobal->tmLastSend > (phglobal->nUserType >= 1 ? 30 : 60)) { SendKeepAlive(phglobal, UDP_OPCODE_UPDATE_VER2); phglobal->tmLastSend = time(0); } ret = RecvKeepaliveResponse(phglobal); if (ret != okNormal && ret != okNoData) phglobal->cLastResult = ret; if (ret == errorOccupyReconnect) { LOG(1) ("RecvKeepaliveResponse failed, waiting for 30 seconds to reconnect...\n"); phglobal->bNeed_connect = TRUE; phglobal->bTcpUpdateSuccessed = FALSE; return 30; } else { if (ret == okKeepAliveRecved) { struct in_addr t; t.s_addr = phglobal->ip; LOG(1) ("Keepalive response received, client ip: %s\n",inet_ntoa(t)); if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, phglobal->ip); } } if (time(0) - phglobal->tmLastResponse > (phglobal->nUserType >= 1 ? 160 : 320) && phglobal->tmLastResponse != -1) { LOG(1) ("No response from server for %d seconds, reconnect immediately...\n", (phglobal->nUserType == 1 ? 160 : 320)); phglobal->bTcpUpdateSuccessed = FALSE; phglobal->bNeed_connect = TRUE; return 1; } } return 1; }
bool RunMixed(ZipfDistribution &zipf, FastRandom &rng) { auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); concurrency::Transaction *txn = txn_manager.BeginTransaction(); std::unique_ptr<executor::ExecutorContext> context( new executor::ExecutorContext(txn)); // Column ids to be added to logical tile. std::vector<oid_t> column_ids; oid_t column_count = state.column_count + 1; // read all the attributes in a tuple. for (oid_t col_itr = 0; col_itr < column_count; col_itr++) { column_ids.push_back(col_itr); } // Create and set up index scan executor std::vector<oid_t> key_column_ids; std::vector<ExpressionType> expr_types; key_column_ids.push_back(0); expr_types.push_back(ExpressionType::EXPRESSION_TYPE_COMPARE_EQUAL); std::vector<expression::AbstractExpression *> runtime_keys; for (int i = 0; i < state.operation_count; i++) { auto rng_val = rng.NextUniform(); if (rng_val < state.update_ratio) { ///////////////////////////////////////////////////////// // PERFORM UPDATE ///////////////////////////////////////////////////////// // set up parameter values std::vector<type::Value > values; auto lookup_key = zipf.GetNextNumber(); values.push_back(type::ValueFactory::GetIntegerValue(lookup_key).Copy()); auto ycsb_pkey_index = user_table->GetIndexWithOid(user_table_pkey_index_oid); planner::IndexScanPlan::IndexScanDesc index_scan_desc( ycsb_pkey_index, key_column_ids, expr_types, values, runtime_keys); // Create plan node. auto predicate = nullptr; planner::IndexScanPlan index_scan_node(user_table, predicate, column_ids, index_scan_desc); // Run the executor executor::IndexScanExecutor index_scan_executor(&index_scan_node, context.get()); TargetList target_list; DirectMapList direct_map_list; // update multiple attributes for (oid_t col_itr = 0; col_itr < column_count; col_itr++) { if (col_itr == 1) { if (state.string_mode == true) { std::string update_raw_value(100, 'a'); type::Value update_val = type::ValueFactory::GetVarcharValue(update_raw_value).Copy(); target_list.emplace_back( col_itr, expression::ExpressionUtil::ConstantValueFactory(update_val)); } else { int update_raw_value = 1; type::Value update_val = type::ValueFactory::GetIntegerValue(update_raw_value).Copy(); target_list.emplace_back( col_itr, expression::ExpressionUtil::ConstantValueFactory(update_val)); } } else { direct_map_list.emplace_back(col_itr, std::pair<oid_t, oid_t>(0, col_itr)); } } std::unique_ptr<const planner::ProjectInfo> project_info( new planner::ProjectInfo(std::move(target_list), std::move(direct_map_list))); planner::UpdatePlan update_node(user_table, std::move(project_info)); executor::UpdateExecutor update_executor(&update_node, context.get()); update_executor.AddChild(&index_scan_executor); ExecuteUpdate(&update_executor); if (txn->GetResult() != Result::RESULT_SUCCESS) { txn_manager.AbortTransaction(txn); return false; } } else { ///////////////////////////////////////////////////////// // PERFORM READ ///////////////////////////////////////////////////////// // set up parameter values std::vector<type::Value > values; auto lookup_key = zipf.GetNextNumber(); values.push_back(type::ValueFactory::GetIntegerValue(lookup_key).Copy()); auto ycsb_pkey_index = user_table->GetIndexWithOid(user_table_pkey_index_oid); planner::IndexScanPlan::IndexScanDesc index_scan_desc( ycsb_pkey_index, key_column_ids, expr_types, values, runtime_keys); // Create plan node. auto predicate = nullptr; planner::IndexScanPlan index_scan_node(user_table, predicate, column_ids, index_scan_desc); // Run the executor executor::IndexScanExecutor index_scan_executor(&index_scan_node, context.get()); ExecuteRead(&index_scan_executor); if (txn->GetResult() != Result::RESULT_SUCCESS) { txn_manager.AbortTransaction(txn); return false; } } } // transaction passed execution. PL_ASSERT(txn->GetResult() == Result::RESULT_SUCCESS); auto result = txn_manager.CommitTransaction(txn); if (result == Result::RESULT_SUCCESS) { return true; } else { // transaction failed commitment. PL_ASSERT(result == Result::RESULT_ABORTED || result == Result::RESULT_FAILURE); return false; } }
bool RunDelivery(const size_t &thread_id) { /* "DELIVERY": { "getNewOrder": "SELECT NO_O_ID FROM NEW_ORDER WHERE NO_D_ID = ? AND NO_W_ID = ? AND NO_O_ID > -1 LIMIT 1", # "deleteNewOrder": "DELETE FROM NEW_ORDER WHERE NO_D_ID = ? AND NO_W_ID = ? AND NO_O_ID = ?", # d_id, w_id, no_o_id "getCId": "SELECT O_C_ID FROM ORDERS WHERE O_ID = ? AND O_D_ID = ? AND O_W_ID = ?", # no_o_id, d_id, w_id "updateOrders": "UPDATE ORDERS SET O_CARRIER_ID = ? WHERE O_ID = ? AND O_D_ID = ? AND O_W_ID = ?", # o_carrier_id, no_o_id, d_id, w_id "updateOrderLine": "UPDATE ORDER_LINE SET OL_DELIVERY_D = ? WHERE OL_O_ID = ? AND OL_D_ID = ? AND OL_W_ID = ?", # o_entry_d, no_o_id, d_id, w_id "sumOLAmount": "SELECT SUM(OL_AMOUNT) FROM ORDER_LINE WHERE OL_O_ID = ? AND OL_D_ID = ? AND OL_W_ID = ?", # no_o_id, d_id, w_id "updateCustomer": "UPDATE CUSTOMER SET C_BALANCE = C_BALANCE + ? WHERE C_ID = ? AND C_D_ID = ? AND C_W_ID = ?", # ol_total, c_id, d_id, w_id } */ LOG_TRACE("-------------------------------------"); ///////////////////////////////////////////////////////// // PREPARE ARGUMENTS ///////////////////////////////////////////////////////// int warehouse_id = GenerateWarehouseId(thread_id); int o_carrier_id = GetRandomInteger(orders_min_carrier_id, orders_max_carrier_id); std::vector<expression::AbstractExpression *> runtime_keys; ///////////////////////////////////////////////////////// // BEGIN TRANSACTION ///////////////////////////////////////////////////////// auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); auto txn = txn_manager.BeginTransaction(thread_id); std::unique_ptr<executor::ExecutorContext> context( new executor::ExecutorContext(txn)); for (int d_id = 0; d_id < state.districts_per_warehouse; ++d_id) { LOG_TRACE( "getNewOrder: SELECT NO_O_ID FROM NEW_ORDER WHERE NO_D_ID = ? AND " "NO_W_ID = ? AND NO_O_ID > -1 LIMIT 1"); // Construct index scan executor std::vector<oid_t> new_order_column_ids = {COL_IDX_NO_O_ID}; std::vector<oid_t> new_order_key_column_ids = { COL_IDX_NO_D_ID, COL_IDX_NO_W_ID, COL_IDX_NO_O_ID}; std::vector<ExpressionType> new_order_expr_types; new_order_expr_types.push_back(ExpressionType::COMPARE_EQUAL); new_order_expr_types.push_back(ExpressionType::COMPARE_EQUAL); new_order_expr_types.push_back(ExpressionType::COMPARE_GREATERTHAN); std::vector<type::Value> new_order_key_values; new_order_key_values.push_back( type::ValueFactory::GetIntegerValue(d_id).Copy()); new_order_key_values.push_back( type::ValueFactory::GetIntegerValue(warehouse_id).Copy()); new_order_key_values.push_back( type::ValueFactory::GetIntegerValue(-1).Copy()); planner::IndexScanPlan::IndexScanDesc new_order_idex_scan_desc( new_order_table_pkey_index_oid, new_order_key_column_ids, new_order_expr_types, new_order_key_values, runtime_keys); planner::IndexScanPlan new_order_idex_scan_node(new_order_table, nullptr, new_order_column_ids, new_order_idex_scan_desc); executor::IndexScanExecutor new_order_index_scan_executor( &new_order_idex_scan_node, context.get()); // Construct limit executor size_t limit = 1; size_t offset = 0; planner::LimitPlan limit_node(limit, offset); executor::LimitExecutor limit_executor(&limit_node, context.get()); limit_executor.AddChild(&new_order_index_scan_executor); auto new_order_ids = ExecuteRead(&limit_executor); if (txn->GetResult() != ResultType::SUCCESS) { LOG_TRACE("abort transaction"); txn_manager.AbortTransaction(txn); return false; } if (new_order_ids.size() == 0) { // TODO: No orders for this district: skip it. Note: This must be // reported if > 1% continue; } assert(new_order_ids.size() == 1); assert(new_order_ids[0].size() == 1); // result: NO_O_ID auto no_o_id = new_order_ids[0][0]; LOG_TRACE("no_o_id = %d", type::ValuePeeker::PeekInteger(no_o_id)); LOG_TRACE( "getCId: SELECT O_C_ID FROM ORDERS WHERE O_ID = ? AND O_D_ID = ? AND " "O_W_ID = ?"); std::vector<oid_t> orders_column_ids = {COL_IDX_O_C_ID}; std::vector<oid_t> orders_key_column_ids = {COL_IDX_O_ID, COL_IDX_O_D_ID, COL_IDX_O_W_ID}; std::vector<ExpressionType> orders_expr_types; orders_expr_types.push_back(ExpressionType::COMPARE_EQUAL); orders_expr_types.push_back(ExpressionType::COMPARE_EQUAL); orders_expr_types.push_back(ExpressionType::COMPARE_EQUAL); std::vector<type::Value> orders_key_values; orders_key_values.push_back(no_o_id); orders_key_values.push_back( type::ValueFactory::GetIntegerValue(d_id).Copy()); orders_key_values.push_back( type::ValueFactory::GetIntegerValue(warehouse_id).Copy()); planner::IndexScanPlan::IndexScanDesc orders_index_scan_desc( orders_table_pkey_index_oid, orders_key_column_ids, orders_expr_types, orders_key_values, runtime_keys); // Create the index scan plan node planner::IndexScanPlan orders_index_scan_node( orders_table, nullptr, orders_column_ids, orders_index_scan_desc); // Create the executors executor::IndexScanExecutor orders_index_scan_executor( &orders_index_scan_node, context.get()); auto orders_ids = ExecuteRead(&orders_index_scan_executor); if (txn->GetResult() != ResultType::SUCCESS) { LOG_TRACE("abort transaction"); txn_manager.AbortTransaction(txn); return false; } assert(orders_ids.size() == 1); assert(orders_ids[0].size() == 1); // Result: O_C_ID auto c_id = orders_ids[0][0]; LOG_TRACE( "sumOLAmount: SELECT SUM(OL_AMOUNT) FROM ORDER_LINE WHERE OL_O_ID = ? " "AND OL_D_ID = ? AND OL_W_ID = ?"); // Construct index scan executor std::vector<oid_t> order_line_column_ids = {COL_IDX_OL_AMOUNT}; std::vector<oid_t> order_line_key_column_ids = { COL_IDX_OL_O_ID, COL_IDX_OL_D_ID, COL_IDX_OL_W_ID}; std::vector<ExpressionType> order_line_expr_types; order_line_expr_types.push_back(ExpressionType::COMPARE_EQUAL); order_line_expr_types.push_back(ExpressionType::COMPARE_EQUAL); order_line_expr_types.push_back(ExpressionType::COMPARE_EQUAL); std::vector<type::Value> order_line_key_values; order_line_key_values.push_back(no_o_id); order_line_key_values.push_back( type::ValueFactory::GetIntegerValue(d_id).Copy()); order_line_key_values.push_back( type::ValueFactory::GetIntegerValue(warehouse_id).Copy()); planner::IndexScanPlan::IndexScanDesc order_line_index_scan_desc( order_line_table_pkey_index_oid, order_line_key_column_ids, order_line_expr_types, order_line_key_values, runtime_keys); planner::IndexScanPlan order_line_index_scan_node( order_line_table, nullptr, order_line_column_ids, order_line_index_scan_desc); executor::IndexScanExecutor order_line_index_scan_executor( &order_line_index_scan_node, context.get()); auto order_line_index_scan_res = ExecuteRead(&order_line_index_scan_executor); if (txn->GetResult() != ResultType::SUCCESS) { LOG_TRACE("abort transaction"); txn_manager.AbortTransaction(txn); return false; } double sum_res = 0.0; // Workaround: Externanl sum for (auto v : order_line_index_scan_res) { assert(v.size() == 1); sum_res += type::ValuePeeker::PeekDouble(v[0]); } auto ol_total = type::ValueFactory::GetDecimalValue(sum_res); LOG_TRACE( "deleteNewOrder: DELETE FROM NEW_ORDER WHERE NO_D_ID = ? AND NO_W_ID = " "? AND NO_O_ID = ?"); // Construct index scan executor std::vector<oid_t> new_order_delete_column_ids = {0}; std::vector<ExpressionType> new_order_delete_expr_types; new_order_delete_expr_types.push_back(ExpressionType::COMPARE_EQUAL); new_order_delete_expr_types.push_back(ExpressionType::COMPARE_EQUAL); new_order_delete_expr_types.push_back(ExpressionType::COMPARE_EQUAL); std::vector<type::Value> new_order_delete_key_values; new_order_delete_key_values.push_back( type::ValueFactory::GetIntegerValue(d_id).Copy()); new_order_delete_key_values.push_back( type::ValueFactory::GetIntegerValue(warehouse_id).Copy()); new_order_delete_key_values.push_back(no_o_id); planner::IndexScanPlan::IndexScanDesc new_order_delete_idex_scan_desc( new_order_table_pkey_index_oid, new_order_key_column_ids, new_order_delete_expr_types, new_order_delete_key_values, runtime_keys); // Create index scan plan node planner::IndexScanPlan new_order_delete_idex_scan_node( new_order_table, nullptr, new_order_delete_column_ids, new_order_delete_idex_scan_desc); // Create executors executor::IndexScanExecutor new_order_delete_index_scan_executor( &new_order_delete_idex_scan_node, context.get()); // Construct delete executor planner::DeletePlan new_order_delete_node(new_order_table); executor::DeleteExecutor new_order_delete_executor(&new_order_delete_node, context.get()); new_order_delete_executor.AddChild(&new_order_delete_index_scan_executor); // Execute the query ExecuteDelete(&new_order_delete_executor); // Check if aborted if (txn->GetResult() != ResultType::SUCCESS) { LOG_TRACE("abort transaction"); txn_manager.AbortTransaction(txn); return false; } LOG_TRACE( "updateOrders: UPDATE ORDERS SET O_CARRIER_ID = ? WHERE O_ID = ? AND " "O_D_ID = ? AND O_W_ID = ?"); // Construct index scan executor std::vector<oid_t> orders_update_column_ids = {COL_IDX_O_CARRIER_ID}; std::vector<type::Value> orders_update_key_values; orders_update_key_values.push_back(no_o_id); orders_update_key_values.push_back( type::ValueFactory::GetIntegerValue(d_id).Copy()); orders_update_key_values.push_back( type::ValueFactory::GetIntegerValue(warehouse_id).Copy()); planner::IndexScanPlan::IndexScanDesc orders_update_index_scan_desc( orders_table_pkey_index_oid, orders_key_column_ids, orders_expr_types, orders_update_key_values, runtime_keys); // Reuse the index scan desc created above since nothing different planner::IndexScanPlan orders_update_index_scan_node( orders_table, nullptr, orders_update_column_ids, orders_update_index_scan_desc); executor::IndexScanExecutor orders_update_index_scan_executor( &orders_update_index_scan_node, context.get()); // Construct update executor TargetList orders_target_list; DirectMapList orders_direct_map_list; size_t orders_column_count = 8; for (oid_t col_itr = 0; col_itr < orders_column_count; col_itr++) { // Skip O_CARRIER_ID if (col_itr != COL_IDX_O_CARRIER_ID) { orders_direct_map_list.emplace_back(col_itr, std::make_pair(0, col_itr)); } } type::Value orders_update_val = type::ValueFactory::GetIntegerValue(o_carrier_id).Copy(); planner::DerivedAttribute carrier_id{ expression::ExpressionUtil::ConstantValueFactory(orders_update_val)}; orders_target_list.emplace_back(COL_IDX_O_CARRIER_ID, carrier_id); std::unique_ptr<const planner::ProjectInfo> orders_project_info( new planner::ProjectInfo(std::move(orders_target_list), std::move(orders_direct_map_list))); planner::UpdatePlan orders_update_node(orders_table, std::move(orders_project_info)); executor::UpdateExecutor orders_update_executor(&orders_update_node, context.get()); orders_update_executor.AddChild(&orders_update_index_scan_executor); // Execute the query ExecuteUpdate(&orders_update_executor); if (txn->GetResult() != ResultType::SUCCESS) { LOG_TRACE("abort transaction"); txn_manager.AbortTransaction(txn); return false; } LOG_TRACE( "updateOrderLine: UPDATE ORDER_LINE SET OL_DELIVERY_D = ? WHERE " "OL_O_ID = ? AND OL_D_ID = ? AND OL_W_ID = ?"); // Construct index scan executor std::vector<oid_t> order_line_update_column_ids = {COL_IDX_OL_DELIVERY_D}; std::vector<type::Value> order_line_update_key_values; order_line_update_key_values.push_back(no_o_id); order_line_update_key_values.push_back( type::ValueFactory::GetIntegerValue(d_id).Copy()); order_line_update_key_values.push_back( type::ValueFactory::GetIntegerValue(warehouse_id).Copy()); planner::IndexScanPlan::IndexScanDesc order_line_update_index_scan_desc( order_line_table_pkey_index_oid, order_line_key_column_ids, order_line_expr_types, order_line_update_key_values, runtime_keys); planner::IndexScanPlan order_line_update_index_scan_node( order_line_table, nullptr, order_line_update_column_ids, order_line_update_index_scan_desc); executor::IndexScanExecutor order_line_update_index_scan_executor( &order_line_update_index_scan_node, context.get()); // Construct update executor TargetList order_line_target_list; DirectMapList order_line_direct_map_list; size_t order_line_column_count = 10; for (oid_t col_itr = 0; col_itr < order_line_column_count; col_itr++) { // Skip OL_DELIVERY_D if (col_itr != COL_IDX_OL_DELIVERY_D) { order_line_direct_map_list.emplace_back(col_itr, std::make_pair(0, col_itr)); } } type::Value order_line_update_val = type::ValueFactory::GetTimestampValue(0).Copy(); planner::DerivedAttribute delivery_id{ expression::ExpressionUtil::ConstantValueFactory( order_line_update_val)}; order_line_target_list.emplace_back(COL_IDX_OL_DELIVERY_D, delivery_id); std::unique_ptr<const planner::ProjectInfo> order_line_project_info( new planner::ProjectInfo(std::move(order_line_target_list), std::move(order_line_direct_map_list))); planner::UpdatePlan order_line_update_node( order_line_table, std::move(order_line_project_info)); executor::UpdateExecutor order_line_update_executor(&order_line_update_node, context.get()); order_line_update_executor.AddChild(&order_line_update_index_scan_executor); ExecuteUpdate(&order_line_update_executor); if (txn->GetResult() != ResultType::SUCCESS) { LOG_TRACE("abort transaction"); txn_manager.AbortTransaction(txn); return false; } LOG_TRACE( "updateCustomer: UPDATE CUSTOMER SET C_BALANCE = C_BALANCE + ? WHERE " "C_ID = ? AND C_D_ID = ? AND C_W_ID = ?"); // Construct index scan executor std::vector<oid_t> customer_column_ids = {COL_IDX_C_BALANCE}; std::vector<oid_t> customer_key_column_ids = {COL_IDX_C_ID, COL_IDX_C_D_ID, COL_IDX_C_W_ID}; std::vector<ExpressionType> customer_expr_types; customer_expr_types.push_back(ExpressionType::COMPARE_EQUAL); customer_expr_types.push_back(ExpressionType::COMPARE_EQUAL); customer_expr_types.push_back(ExpressionType::COMPARE_EQUAL); std::vector<type::Value> customer_key_values; customer_key_values.push_back(c_id); customer_key_values.push_back( type::ValueFactory::GetIntegerValue(d_id).Copy()); customer_key_values.push_back( type::ValueFactory::GetIntegerValue(warehouse_id).Copy()); planner::IndexScanPlan::IndexScanDesc customer_index_scan_desc( customer_table_pkey_index_oid, customer_key_column_ids, customer_expr_types, customer_key_values, runtime_keys); planner::IndexScanPlan customer_index_scan_node( customer_table, nullptr, customer_column_ids, customer_index_scan_desc); executor::IndexScanExecutor customer_index_scan_executor( &customer_index_scan_node, context.get()); // Construct update executor TargetList customer_target_list; DirectMapList customer_direct_map_list; size_t customer_column_count = 21; for (oid_t col_itr = 0; col_itr < customer_column_count; col_itr++) { // Skip OL_DELIVERY_D if (col_itr != COL_IDX_C_BALANCE) { customer_direct_map_list.emplace_back(col_itr, std::make_pair(0, col_itr)); } } // Expressions // Tuple value expression auto tuple_val_expr = expression::ExpressionUtil::TupleValueFactory( type::TypeId::INTEGER, 0, COL_IDX_C_BALANCE); // Constant value expression auto constant_val_expr = expression::ExpressionUtil::ConstantValueFactory(ol_total); // + operator expression auto plus_operator_expr = expression::ExpressionUtil::OperatorFactory( ExpressionType::OPERATOR_PLUS, type::TypeId::INTEGER, tuple_val_expr, constant_val_expr); planner::DerivedAttribute c_balance{plus_operator_expr}; customer_target_list.emplace_back(COL_IDX_C_BALANCE, c_balance); std::unique_ptr<const planner::ProjectInfo> customer_project_info( new planner::ProjectInfo(std::move(customer_target_list), std::move(customer_direct_map_list))); planner::UpdatePlan customer_update_node(customer_table, std::move(customer_project_info)); executor::UpdateExecutor customer_update_executor(&customer_update_node, context.get()); customer_update_executor.AddChild(&customer_index_scan_executor); // Execute the query ExecuteUpdate(&customer_update_executor); if (txn->GetResult() != ResultType::SUCCESS) { LOG_TRACE("abort transaction"); txn_manager.AbortTransaction(txn); return false; } } assert(txn->GetResult() == ResultType::SUCCESS); auto result = txn_manager.CommitTransaction(txn); if (result == ResultType::SUCCESS) { LOG_TRACE("commit successfully"); return true; } else { assert(result == ResultType::ABORTED || result == ResultType::FAILURE); return false; } }