/*{ ** Name: openTempTable - Open a temp table used for set input ** procedure. ** ** Description: ** The current execution environment is saved and an ** environment is created in which to execute the ** named procedure. ** ** This procedure is only called when a nested procedure is invoked. ** This can occur the first time through, or if the procedure is not ** found (LOAD_QP) or the plan was deemed invalid (INVALID_QUERY) then ** the procedure is re-entered in this routine. ** ** If rules are turned off (QEF_T_NORULES) then this procedure returns ** immediately. ** ** Inputs: ** qef_rcb ** tempTableNumber index to dsh temptable array for temporary ** table to be created. ** ** Outputs: ** Returns: ** E_DB_{OK,WARN,ERROR,FATAL} (from table creation) ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 18-jul-96 (inkdo01) ** Created. ** 29-oct-1998 (somsa01) ** If we are opening a Global Temporary Table, turn on the ** DMT_SESSION_TEMP flag in dmt_flags_mask before the open. ** (Bug #94059) ** 12-nov-1998 (somsa01) ** Added another parameter, and refined the check for a Global ** Session Temporary Table. (Bug #94059) ** 15-mar-04 (inkdo01) ** dsh_tempTables is now an array of ptrs. ** 13-Jul-2004 (schka24) ** Pass in dsh so we get the right one for sure. ** 30-Jul-2004 (jenjo02) ** Use dsh_dmt_id rather than qef_dmt_id transaction context. ** 4-Jun-2009 (kschendel) b122118 ** Use open-and-link utility. */ static DB_STATUS openTempTable( QEF_RCB *rcb, QEE_DSH *dsh, i4 tempTableNumber, bool gttparm ) { QEE_TEMP_TABLE *tempTable = dsh->dsh_tempTables[ tempTableNumber ]; DMT_CB *dmt = tempTable->tt_dmtcb; DMR_CB *dmr = tempTable->tt_dmrcb; DM_MDATA dm_mdata; DB_STATUS status = E_DB_OK; for (;;) /* something to break out of */ { /* create the table if it doesn't already exist */ if ( !( tempTable->tt_statusFlags & TT_CREATED ) ) { dmt->dmt_db_id = rcb->qef_db_id; dmt->dmt_tran_id = dsh->dsh_dmt_id; MEmove(8, (PTR) "$default", (char) ' ', sizeof(DB_LOC_NAME), (PTR) dmt->dmt_location.data_address); dmt->dmt_location.data_in_size = sizeof(DB_LOC_NAME); dmt->dmt_flags_mask = DMT_DBMS_REQUEST; if (gttparm) dmt->dmt_flags_mask |= DMT_SESSION_TEMP; dmr->dmr_flags_mask = 0; /* ** We assume that the sort key descriptor was set up ** earlier, probably at QEE time. */ if ( tempTable->tt_statusFlags & TT_PLEASE_SORT ) dmt->dmt_flags_mask |= DMT_LOAD; if ( tempTable->tt_statusFlags & TT_NO_DUPLICATES ) dmr->dmr_flags_mask |= DMR_NODUPLICATES; dmr->dmr_count = 1; dmr->dmr_s_estimated_records = TT_TUPLE_COUNT_GUESS; dmr->dmr_tid = 0; dm_mdata.data_address = dsh->dsh_row[ tempTable->tt_tuple ]; dm_mdata.data_size = dsh->dsh_qp_ptr->qp_row_len[ tempTable->tt_tuple ]; dmr->dmr_mdata = &dm_mdata; status = dmf_call(DMT_CREATE_TEMP, dmt); if (status != E_DB_OK) { if (dmt->error.err_code == E_DM0078_TABLE_EXISTS) { dsh->dsh_error.err_code = E_QE0050_TEMP_TABLE_EXISTS; status = E_DB_ERROR; } else { dsh->dsh_error.err_code = dmt->error.err_code; } break; } /* Open the temp table */ dmt->dmt_flags_mask = 0; if (gttparm) dmt->dmt_flags_mask |= DMT_SESSION_TEMP; dmt->dmt_sequence = dsh->dsh_stmt_no; dmt->dmt_access_mode = DMT_A_WRITE; dmt->dmt_lock_mode = DMT_X; dmt->dmt_update_mode = DMT_U_DIRECT; status = qen_openAndLink(dmt, dsh); if (status != E_DB_OK) { break; } tempTable->tt_statusFlags |= TT_CREATED; dmr->dmr_access_id = dmt->dmt_record_access_id; } /* end of table creation */ break; } /* end of code block */ return( status ); }
static DB_STATUS qen_ts_dump( QEN_SHD *shd, QEE_DSH *dsh, QEN_NODE *node, i4 rowno, bool heap_sort, bool no_qef ) { PTR *cbs = dsh->dsh_cbs; DMT_CB *dmt = (DMT_CB *)cbs[node->node_qen.qen_tsort.tsort_create]; DMR_CB *dmr_load = (DMR_CB*)cbs[node->node_qen.qen_tsort.tsort_load]; DMR_CB *dmr_get = (DMR_CB*) cbs[node->node_qen.qen_tsort.tsort_get]; DMT_CHAR_ENTRY char_array[2]; DB_STATUS status; for (;;) /* to break off in case of error */ { /* Initialize the DMT_CB for the sorter table */ dmt->dmt_flags_mask = DMT_LOAD | DMT_DBMS_REQUEST; dmt->dmt_db_id = dsh->dsh_qefcb->qef_rcb->qef_db_id; dmt->dmt_tran_id = dsh->dsh_dmt_id; MEmove(8, (PTR) "$default", (char) ' ', sizeof(DB_LOC_NAME), (PTR) dmt->dmt_location.data_address); dmt->dmt_location.data_in_size = sizeof(DB_LOC_NAME); /* Initialize table attribute descriptors */ dmt->dmt_attr_array.ptr_address = (PTR) node->node_qen.qen_tsort.tsort_atts; dmt->dmt_attr_array.ptr_in_count = node->node_qen.qen_tsort.tsort_acount; dmt->dmt_attr_array.ptr_size = sizeof (DMF_ATTR_ENTRY); /* Initialize the the sort key descriptors */ dmt->dmt_key_array.ptr_address = (PTR) node->node_qen.qen_tsort.tsort_satts; dmt->dmt_key_array.ptr_in_count = node->node_qen.qen_tsort.tsort_scount; dmt->dmt_key_array.ptr_size = sizeof (DMT_KEY_ENTRY); /* Pass the page size */ char_array[0].char_id = DMT_C_PAGE_SIZE; char_array[0].char_value = node->node_qen.qen_tsort.tsort_pagesize; char_array[1].char_id = DMT_C_DUPLICATES; char_array[1].char_value = DMT_C_ON; /* duplicate rows allowed */ dmt->dmt_char_array.data_address = (PTR) &char_array; dmt->dmt_char_array.data_in_size = 2 * sizeof(DMT_CHAR_ENTRY); /* Create the sorter table */ status = dmf_call(DMT_CREATE_TEMP, dmt); if (status != E_DB_OK) { if (dmt->error.err_code == E_DM0078_TABLE_EXISTS) { dsh->dsh_error.err_code = E_QE0050_TEMP_TABLE_EXISTS; status = E_DB_ERROR; } else { dsh->dsh_error.err_code = dmt->error.err_code; } break; } /* Open the sorter table */ dmt->dmt_flags_mask = 0; dmt->dmt_sequence = dsh->dsh_stmt_no; dmt->dmt_access_mode = DMT_A_WRITE; dmt->dmt_lock_mode = DMT_X; dmt->dmt_update_mode = DMT_U_DIRECT; dmt->dmt_char_array.data_address = 0; dmt->dmt_char_array.data_in_size = 0; status = qen_openAndLink(dmt, dsh); if (status != E_DB_OK) { break; } /* Initialize the DMR_CB for loading the sorter */ dmr_load->dmr_access_id = dmt->dmt_record_access_id; dmr_load->dmr_count = 1; dmr_load->dmr_flags_mask = (node->node_qen.qen_tsort.tsort_dups | DMR_SORT_NOCOPY); dmr_load->dmr_s_estimated_records = node->qen_est_tuples; dmr_load->dmr_tid = 0; /* Initialize the DMR_CB for reading the sorter */ dmr_get->dmr_access_id = dmt->dmt_record_access_id; dmr_get->dmr_data.data_address = dsh->dsh_row[rowno]; dmr_get->dmr_data.data_in_size = dsh->dsh_qp_ptr->qp_row_len[rowno]; dmr_get->dmr_tid = 0; if (no_qef) break; /* leave, if nothing there */ /* If we have tuples in the in-memory sort buffer, load them into ** DMF sorter table now and write current tuple. */ if (heap_sort) status = qes_dump(dsh, shd, dmr_load); else status = qes_dumploop(dsh, shd, dmr_load); break; } /* end of error-break loop */ return (status); }