dbe_key_t * setp_temp_key (setp_node_t * setp, long *row_len_ptr, int quietcast) { int inx = 0; NEW_VARZ (dbe_key_t, key); key->key_n_significant = dk_set_length (setp->setp_keys); key->key_id = KI_TEMP; key->key_is_primary = 0; key->key_super_id = KI_TEMP; DO_SET (state_slot_t *, ssl, &setp->setp_keys) { if (row_len_ptr) *row_len_ptr += sqt_row_data_length (& ssl->ssl_sqt); key_col_from_ssl (key, ssl, quietcast, NULL); } END_DO_SET(); DO_SET (state_slot_t *, ssl, &setp->setp_dependent) { gb_op_t *gb_op = dk_set_nth (setp->setp_gb_ops, inx); if (row_len_ptr) *row_len_ptr += sqt_row_data_length (& ssl->ssl_sqt); key_col_from_ssl (key, ssl, quietcast, gb_op); inx ++; } END_DO_SET(); dbe_key_layout (key, NULL); dk_set_push (&setp->src_gen.src_query->qr_temp_keys, (void*) key); return key; }
caddr_t DBG_HASHEXT_NAME(id_casemode_hash_set) (DBG_PARAMS id_hash_t * ht, caddr_t _qn, caddr_t _o, caddr_t data) { id_casemode_entry_llist_t **list; caddr_t ret; list = (id_casemode_entry_llist_t **) id_hash_get (ht, (caddr_t) &_qn); if (list) { id_casemode_entry_llist_t *iter = *list; while (iter) { if (casemode_strhashcmp ((char *) &(iter->owner), (char *) &_o)) { caddr_t old_value = *((caddr_t *)iter->data); iter->data = data; ret = old_value; break; } iter = iter->next; } if (!iter) { NEW_VARZ (id_casemode_entry_llist_t, new_iter); new_iter->owner = _o; new_iter->data = *((caddr_t *)data); new_iter->next = *list; *list = new_iter; ret = NULL; } } else { NEW_VARZ (id_casemode_entry_llist_t, new_iter); new_iter->owner = _o; new_iter->data = *((caddr_t *)data); DBG_HASHEXT_NAME (id_hash_set) (DBG_ARGS ht, (caddr_t)&_qn, (caddr_t) &new_iter); ret = NULL; } return ret; }
dk_mutex_t * mutex_allocate (void) { NEW_VARZ (dk_mutex_t, mtx); mtx->mtx_handle = semaphore_allocate (1); #ifdef MTX_DEBUG mtx->mtx_owner = NULL; dk_set_push (&all_mtxs, (void*)mtx); #endif return mtx; }
dk_mutex_t * mutex_allocate_typed (int type) { int rc; static int is_initialized = 0; NEW_VARZ (dk_mutex_t, mtx); mtx->mtx_type = type; #if HAVE_SPINLOCK if (MUTEX_TYPE_SPIN == type) { pthread_spin_init (&mtx->l.spinl, 0); } else #endif { memset ((void *) &mtx->mtx_mtx, 0, sizeof (pthread_mutex_t)); #ifndef OLD_PTHREADS if (!is_initialized) { pthread_mutexattr_init (&_mutex_attr); #if defined (PTHREAD_PROCESS_PRIVATE) && !defined(oldlinux) && !defined (__FreeBSD__) rc = pthread_mutexattr_setpshared (&_mutex_attr, PTHREAD_PROCESS_PRIVATE); CKRET (rc); #endif #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP rc = pthread_mutexattr_settype (&_mutex_attr, PTHREAD_MUTEX_ADAPTIVE_NP); CKRET (rc); #endif is_initialized = 1; } rc = pthread_mutex_init (&mtx->mtx_mtx, &_mutex_attr); #else rc = pthread_mutex_init (&mtx->mtx_mtx, _mutex_attr); #endif CKRET (rc); } #ifdef MTX_DEBUG mtx->mtx_owner = NULL; #endif #ifdef MTX_METER if (all_mtxs_mtx) mutex_enter (all_mtxs_mtx); dk_set_push (&all_mtxs, (void*)mtx); if (all_mtxs_mtx) mutex_leave (all_mtxs_mtx); #endif return mtx; failed: dk_free (mtx, sizeof (dk_mutex_t)); return NULL; }
void key_col_from_ssl (dbe_key_t * key, state_slot_t * ssl, int quietcast, gb_op_t *gb_op) { NEW_VARZ (dbe_column_t, col); col->col_name = box_dv_short_string (SSL_HAS_NAME (ssl) ? ssl->ssl_name : "const"); col->col_compression = CC_NONE; col->col_sqt = ssl->ssl_sqt; col->col_sqt.sqt_non_null = 0; if (DV_LONG_INT == ssl->ssl_dtp && !ssl->ssl_column) col->col_sqt.sqt_dtp = DV_INT64; /* temp results of int exprs can be wider */ if (DV_IRI_ID == col->col_sqt.sqt_dtp) col->col_sqt.sqt_dtp = DV_IRI_ID_8; if (DV_UNKNOWN == col->col_sqt.sqt_dtp || (!dtp_is_fixed (col->col_sqt.sqt_dtp) && !dtp_is_var (col->col_sqt.sqt_dtp))) { col->col_sqt.sqt_dtp = quietcast ? DV_ANY : DV_LONG_STRING; col->col_sqt.sqt_precision = 0; } /* turn off length checking for temp cols for now */ if (col->col_sqt.sqt_dtp == DV_LONG_STRING || col->col_sqt.sqt_dtp == DV_ANY) col->col_sqt.sqt_precision = 0; if (gb_op && col->col_sqt.sqt_dtp == DV_ANY) { switch (gb_op->go_op) { case AMMSC_COUNT: col->col_sqt.sqt_dtp = DV_INT64; col->col_sqt.sqt_precision = DV_LONG_INT_PREC; break; case AMMSC_COUNTSUM: case AMMSC_SUM: case AMMSC_AVG: col->col_sqt.sqt_dtp = DV_NUMERIC; col->col_sqt.sqt_precision = NUMERIC_MAX_PRECISION; col->col_sqt.sqt_precision = NUMERIC_MAX_SCALE; break; default: break; } } col->col_id = dk_set_length (key->key_parts) + 1; col->col_options = (caddr_t *) box_copy_tree ((box_t) ssl->ssl_sqt.sqt_tree); NCONCF1 (key->key_parts, col); }
void * export_mts_trx_allocate () { static tp_trx_vtbl_t mts_vtbl = { mts_ms_sql_enlist, mts_trx_commit, mts_trx_commit_stage_2, mts_trx_exclude, mts_trx_dealloc }; NEW_VARZ (tp_dtrx_t, dtrx); dtrx->vtbl = &mts_vtbl; dtrx->dtrx_info = (caddr_t) dk_alloc (sizeof (mts_t)); memset (dtrx->dtrx_info, 0, sizeof (mts_t)); return (void *) dtrx; };
/* * The main thread must call this function to convert itself into a thread. */ thread_t * thread_initial (unsigned long stack_size) { if (_main_thread) return _main_thread; else { NEW_VARZ (thread_t, thr); _main_thread = thr; thr->thr_status = RUNNING; thr->thr_sem = semaphore_allocate (0); thr->thr_schedule_sem = semaphore_allocate (0); _thread_init_attributes (thr); thread_set_priority (thr, NORMAL_PRIORITY); return thr; } }
/* * The main thread must call this function to convert itself into a fiber. */ thread_t * thread_initial (unsigned long stack_size) { static unsigned int marker = THREAD_STACK_MARKER; if (_current_fiber) return _current_fiber; else { NEW_VARZ (thread_t, thr); assert (_current_fiber == NULL); _main_thread = _current_fiber = thr; _sched_init (); if (stack_size == 0) stack_size = MAIN_STACK_SIZE; #if (SIZEOF_VOID_P == 8) stack_size *= 2; #endif #if defined (__x86_64 ) && defined (SOLARIS) /*GK: the LDAP on that platform requires that */ stack_size *= 2; #endif thr->thr_stack_marker = ▮ thr->thr_sem = semaphore_allocate (0); thr->thr_schedule_sem = semaphore_allocate (0); thread_set_priority (thr, NORMAL_PRIORITY); _thread_init_attributes (thr); _fiber_for_thread (thr, stack_size); _fiber_status (thr, RUNNING); return thr; } }
void setp_distinct_hash (sql_comp_t * sc, setp_node_t * setp, long n_rows) { int quietcast = sc->sc_cc->cc_query->qr_no_cast_error; /* This was: int quietcast = DFE_DT == sc->sc_so->so_dfe->dfe_type ? NULL != sqlo_opt_value (sc->sc_so->so_dfe->_.sub.ot->ot_opts, OPT_SPARQL) : 0; */ int inx; int n_keys = dk_set_length (setp->setp_keys); int n_deps = dk_set_length (setp->setp_dependent); NEW_VARZ (hash_area_t, ha); DO_SET (state_slot_t *, ssl, &setp->setp_keys) { if (!quietcast && IS_BLOB_DTP (ssl->ssl_sqt.sqt_dtp)) sqlc_new_error (sc->sc_cc, "42000", "SQ186", "Long data types not allowed for distinct, order, " "group or join condition columns (%s)", ssl->ssl_name); else if (DV_OBJECT == ssl->ssl_sqt.sqt_dtp) sqlc_new_error (sc->sc_cc, "42000", "SQ187", "user defined data types not allowed for distinct, order, " "group or join condition columns (%s)", ssl->ssl_name); } END_DO_SET(); ha->ha_row_size = 0; ha->ha_key = setp_temp_key (setp, &ha->ha_row_size, quietcast); setp->setp_ha = setp->setp_reserve_ha = ha; ha->ha_tree = ssl_new_tree (sc->sc_cc, "DISTINCT HASH"); ha->ha_ref_itc = ssl_new_itc (sc->sc_cc); ha->ha_insert_itc = ssl_new_itc (sc->sc_cc); #ifdef NEW_HASH ha->ha_bp_ref_itc = ssl_new_itc (sc->sc_cc); #endif ha->ha_n_keys = n_keys; ha->ha_n_deps = n_deps; if (n_rows < 0) n_rows = 100000; /* count probably overflowed.- Large amount */ else if (n_rows < 1000) n_rows = 1000; /* no less than 1000 if overflows memcache, must be at least this much */ else if (n_rows > 1000000) n_rows = 1000000; /* have a cap on hash size */ ha->ha_row_count = n_rows; ha->ha_key_cols = (dbe_col_loc_t *) dk_alloc_box_zero ((n_deps + n_keys + 1) * sizeof (dbe_col_loc_t), DV_CUSTOM); for (inx = 0; inx < n_keys + n_deps; inx++) { dbe_col_loc_t * cl = key_find_cl (ha->ha_key, inx +1); ha->ha_key_cols[inx] = cl[0]; if ((inx >= n_keys) && (cl->cl_fixed_len <= 0)) ha->ha_memcache_only = 1; } ha->ha_slots = (state_slot_t **) list_to_array (dk_set_conc (dk_set_copy (setp->setp_keys), dk_set_copy (setp->setp_dependent))); #if 1 if (ha->ha_memcache_only && setp->setp_gb_ops && setp->setp_gb_ops->data) { inx = n_keys; DO_SET (gb_op_t *, op, &(setp->setp_gb_ops)) { state_slot_t * ssl = ha->ha_slots[inx]; switch (op->go_op) { case AMMSC_COUNT: case AMMSC_COUNTSUM: case AMMSC_SUM: case AMMSC_AVG: case AMMSC_MIN: case AMMSC_MAX: { /* check dep part to be numeric type */ if (IS_NUM_DTP (ssl->ssl_dtp)) ha->ha_memcache_only = 0; else { ha->ha_memcache_only = 1; goto check_done; } break; } default: break; } inx++; } END_DO_SET (); check_done:; }