Пример #1
0
/*
 * cursor_open () -
 *   return: true on all ok, false otherwise
 *   cursor_id(out): Cursor identifier
 *   list_id: List file identifier
 *   updatable: Flag which indicates if cursor is updatable
 *   is_oid_included: Flag which indicates if first column of the list file
 *                 contains hidden object identifiers
 *
 * Note: A cursor is opened to scan through the tuples of the given
 *       list file. The cursor identifier is initialized and memory
 *       buffer for the cursor identifier is allocated. If is_oid_included
 *       flag is set to true, this indicates that the first column
 *       of list file tuples contains the object identifier to be used
 *       for cursor update/delete operations.
 */
bool
cursor_open (CURSOR_ID * cursor_id_p, QFILE_LIST_ID * list_id_p,
	     bool updatable, bool is_oid_included)
{
  static QFILE_LIST_ID empty_list_id;	/* TODO: remove static empty_list_id */

  QFILE_CLEAR_LIST_ID (&empty_list_id);

  cursor_id_p->is_updatable = updatable;
  cursor_id_p->is_oid_included = is_oid_included;
  cursor_id_p->oid_ent_count = 0;
  cursor_id_p->oid_set = NULL;
  cursor_id_p->mop_set = NULL;
  cursor_id_p->position = C_BEFORE;
  cursor_id_p->tuple_no = -1;
  VPID_SET_NULL (&cursor_id_p->current_vpid);
  VPID_SET_NULL (&cursor_id_p->next_vpid);
  VPID_SET_NULL (&cursor_id_p->header_vpid);
  cursor_id_p->tuple_record.size = 0;
  cursor_id_p->tuple_record.tpl = NULL;
  cursor_id_p->on_overflow = false;
  cursor_id_p->buffer_tuple_count = 0;
  cursor_id_p->current_tuple_no = -1;
  cursor_id_p->current_tuple_offset = -1;
  cursor_id_p->current_tuple_p = NULL;
  cursor_id_p->current_tuple_length = -1;
  cursor_id_p->oid_col_no = NULL;
  cursor_id_p->oid_col_no_cnt = 0;
  cursor_id_p->buffer = NULL;
  cursor_id_p->buffer_area = NULL;
  cursor_id_p->buffer_filled_size = 0;
  cursor_id_p->list_id = empty_list_id;
  cursor_id_p->prefetch_lock_mode = DB_FETCH_READ;
  cursor_id_p->is_copy_tuple_value = true;	/* copy */
  cursor_initialize_current_tuple_value_position (cursor_id_p);

  if (cursor_copy_list_id (&cursor_id_p->list_id, list_id_p) != NO_ERROR)
    {
      return false;
    }

  if (cursor_id_p->list_id.type_list.type_cnt)
    {
      cursor_id_p->buffer_area = (char *) malloc (CURSOR_BUFFER_AREA_SIZE);
      cursor_id_p->buffer = cursor_id_p->buffer_area;

      if (cursor_id_p->buffer == NULL)
	{
	  return false;
	}

      if (is_oid_included)
	{
	  cursor_allocate_oid_buffer (cursor_id_p);
	}
    }

  return true;
}
Пример #2
0
static int
remote_generate_count_star_xasl (THREAD_ENTRY * thread_p, XASL_NODE ** target,
				 XASL_NODE * src, ACCESS_SPEC_TYPE * spec)
{
  int rc = ER_FAILED;

  if (src == NULL)
    {
      return rc;
    }

  *target = (XASL_NODE *) db_private_alloc (thread_p, sizeof (XASL_NODE));
  if ((*target) == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
	      1, sizeof (XASL_NODE));
      return rc;
    }

  memcpy (*target, src, sizeof (XASL_NODE));

  (*target)->n_oid_list = 0;
  (*target)->outptr_list = (*target)->outptr_list;
  (*target)->remote_outptr_list = NULL;
  (*target)->spec_list = NULL;
  (*target)->curr_spec = NULL;
  (*target)->scan_ptr = NULL;
  (*target)->aptr_list = NULL;
  (*target)->next = NULL;
  (*target)->after_iscan_list = NULL;
  (*target)->ordbynum_flag = 0;
  (*target)->ordbynum_pred = NULL;
  (*target)->ordbynum_val = NULL;
  (*target)->orderby_list = NULL;
  (*target)->instnum_pred = NULL;
  (*target)->instnum_val = NULL;

  (*target)->list_id =
    (QFILE_LIST_ID *) db_private_alloc (thread_p, sizeof (QFILE_LIST_ID));
  if ((*target)->list_id == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1,
	      sizeof (XASL_NODE));
      return rc;
    }

  QFILE_CLEAR_LIST_ID ((*target)->list_id);

  (*target)->spec_list =
    (ACCESS_SPEC_TYPE *) db_private_alloc (thread_p,
					   sizeof (ACCESS_SPEC_TYPE));
  if ((*target)->spec_list == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
	      1, sizeof (ACCESS_SPEC_TYPE));
      return rc;
    }

  memcpy ((*target)->spec_list, spec, sizeof (ACCESS_SPEC_TYPE));
  (*target)->spec_list->s.cls_node.node_id = DB_CLUSTER_NODE_LOCAL;
  (*target)->spec_list->next = NULL;

  rc = NO_ERROR;

  return rc;
}
Пример #3
0
static int
remote_generate_remote_xasl_by_host (THREAD_ENTRY * thread_p,
				     XASL_NODE ** target, XASL_NODE * src,
				     int node_id)
{
  int rc = ER_FAILED;
  ACCESS_SPEC_TYPE *src_spec = NULL, *tar_spec = NULL, *tmp_spec = NULL;

  if (src == NULL)
    {
      return rc;
    }

  *target = (XASL_NODE *) db_private_alloc (thread_p, sizeof (XASL_NODE));
  if ((*target) == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
	      1, sizeof (XASL_NODE));
      return rc;
    }

  memcpy (*target, src, sizeof (XASL_NODE));

  (*target)->n_oid_list = 0;

  if (src->type == BUILDVALUE_PROC
      && src->proc.buildvalue.agg_list->function == PT_COUNT_STAR)
    {
      /* nothing */
      /* temp code */
    }
  else
    {
      (*target)->outptr_list = (*target)->remote_outptr_list;
      (*target)->remote_outptr_list = NULL;
    }

  (*target)->spec_list = NULL;
  (*target)->curr_spec = NULL;
  (*target)->scan_ptr = NULL;
  (*target)->aptr_list = NULL;
  (*target)->next = NULL;
  (*target)->after_iscan_list = NULL;
  (*target)->ordbynum_flag = 0;
  (*target)->ordbynum_pred = NULL;
  (*target)->ordbynum_val = NULL;
  (*target)->orderby_list = NULL;
  (*target)->instnum_pred = NULL;
  (*target)->instnum_val = NULL;

  (*target)->list_id =
    (QFILE_LIST_ID *) db_private_alloc (thread_p, sizeof (QFILE_LIST_ID));
  if ((*target)->list_id == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1,
	      sizeof (XASL_NODE));
      return rc;
    }

  QFILE_CLEAR_LIST_ID ((*target)->list_id);

  src_spec = src->spec_list;

  while (src_spec)
    {
      if (src_spec->s.cls_node.node_id == node_id)
	{
	  tar_spec =
	    (ACCESS_SPEC_TYPE *) db_private_alloc (thread_p,
						   sizeof (ACCESS_SPEC_TYPE));
	  if (tar_spec == NULL)
	    {
	      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE,
		      ER_OUT_OF_VIRTUAL_MEMORY, 1, sizeof (ACCESS_SPEC_TYPE));
	      return rc;
	    }

	  memcpy (tar_spec, src_spec, sizeof (ACCESS_SPEC_TYPE));
	  tar_spec->s.cls_node.node_id = DB_CLUSTER_NODE_LOCAL;
	  tar_spec->next = NULL;

	  if (!(*target)->spec_list)
	    {
	      (*target)->spec_list = tar_spec;
	    }
	  else
	    {
	      tmp_spec = (*target)->spec_list;
	      while (tmp_spec->next)
		{
		  tmp_spec = tmp_spec->next;
		}
	      tmp_spec->next = tar_spec;
	    }

	  XASL_SET_FLAG (src_spec, XASL_SPEC_VISITED);
	}
      src_spec = src_spec->next;
    }

  if ((*target)->type == BUILDVALUE_PROC)
    {
      BUILDLIST_PROC_NODE *bl_proc = &((*target)->proc.buildlist);

      (*target)->type = BUILDLIST_PROC;

      memset (bl_proc, 0, sizeof (BUILDLIST_PROC_NODE));

    }

  rc = NO_ERROR;

  return rc;
}
Пример #4
0
DB_QUERY_RESULT *
pt_new_query_result_descriptor (PARSER_CONTEXT * parser, PT_NODE * query)
{
  int degree;
  DB_QUERY_RESULT *r = NULL;
  QFILE_LIST_ID *list_id;
  int oids_included = 0;
  bool failure = false;

  if (query == NULL)
    {
      return NULL;
    }

  switch (query->node_type)
    {
    default:
      return NULL;
      break;

    case PT_EXECUTE_PREPARE:
      if (query->info.execute.stmt_type != CUBRID_STMT_SELECT)
	{
	  return NULL;
	}
      oids_included = query->info.execute.oids_included;
      degree = query->info.execute.column_count;
      break;

    case PT_INSERT:
      oids_included = 0;
      degree = 1;
      break;

    case PT_DIFFERENCE:
    case PT_INTERSECTION:
    case PT_UNION:
    case PT_SELECT:
      oids_included = query->info.query.oids_included;
      degree = 0;
      degree = pt_length_of_select_list (pt_get_select_list (parser, query), EXCLUDE_HIDDEN_COLUMNS);
      break;
    }

  r = db_alloc_query_result (T_SELECT, degree);
  if (r == NULL)
    {
      return NULL;
    }

  db_init_query_result (r, T_SELECT);
  r->type = T_SELECT;
  r->col_cnt = degree;

  r->oid_included = oids_included == 1;
  r->res.s.query_id = parser->query_id;
  r->res.s.stmt_id = 0;
  r->res.s.stmt_type = CUBRID_STMT_SELECT;
  r->res.s.cache_time = query->cache_time;

  /* the following is for clean up when the query fails */
  memset (&r->res.s.cursor_id.list_id, 0, sizeof (QFILE_LIST_ID));
  r->res.s.cursor_id.query_id = parser->query_id;
  r->res.s.cursor_id.buffer = NULL;
  r->res.s.cursor_id.tuple_record.tpl = NULL;
  r->res.s.holdable = parser->is_holdable;

  list_id = (QFILE_LIST_ID *) query->etc;
  r->type_cnt = degree;
  if (list_id)
    {
      failure = !cursor_open (&r->res.s.cursor_id, list_id, false, r->oid_included);
      /* free result, which was copied by open cursor operation! */
      regu_free_listid (list_id);
    }
  else
    {
      QFILE_LIST_ID empty_list_id;
      QFILE_CLEAR_LIST_ID (&empty_list_id);
      failure = !cursor_open (&r->res.s.cursor_id, &empty_list_id, false, r->oid_included);
    }

  if (failure)
    {
      db_free_query_result (r);
      r = NULL;
    }

  return r;
}