示例#1
0
文件: main.c 项目: DINKIN/mongo
static int
index_compare(WT_COLLATOR *collator, WT_SESSION *session,
	      const WT_ITEM *key1, const WT_ITEM *key2, int *cmp)
{
	WT_ITEM ikey1, pkey1, ikey2, pkey2;

	(void)collator;
	testutil_check(wiredtiger_struct_unpack(session,
	    key1->data, key1->size, "uu", &ikey1, &pkey1));
	testutil_check(wiredtiger_struct_unpack(session,
	    key2->data, key2->size, "uu", &ikey2, &pkey2));

	print_int_item("index_compare: index key1 = ", &ikey1);
	print_int_item(", primary key1 = ", &pkey1);
	print_int_item(", index key2 = ", &ikey2);
	print_int_item(", primary key2 = ", &pkey2);
	printf("\n");

	if ((*cmp = compare_int_items(&ikey1, &ikey2)) != 0)
		return (0);

	if (pkey1.size != 0 && pkey2.size != 0)
		*cmp = compare_int_items(&pkey1, &pkey2);
	else if (pkey1.size != 0)
		*cmp = 1;
	else if (pkey2.size != 0)
		*cmp = -1;
	else
		*cmp = 0;

	return (0);
}
示例#2
0
int
pack_ops(WT_SESSION *session)
{
	int ret;

	{
	/*! [Get the packed size] */
	size_t size;
	ret = wiredtiger_struct_size(session, &size, "iSh", 42, "hello", -3);
	/*! [Get the packed size] */
	assert(size < 100);
	}

	{
	/*! [Pack fields into a buffer] */
	char buf[100];
	ret = wiredtiger_struct_pack(
	    session, buf, sizeof(buf), "iSh", 42, "hello", -3);
	/*! [Pack fields into a buffer] */

	{
	/*! [Unpack fields from a buffer] */
	int i;
	char *s;
	short h;
	ret = wiredtiger_struct_unpack(
	    session, buf, sizeof(buf), "iSh", &i, &s, &h);
	/*! [Unpack fields from a buffer] */
	}
	}

	return (ret);
}
示例#3
0
文件: ex_all.c 项目: ajdavis/mongo
static void
pack_ops(WT_SESSION *session)
{
	{
	/*! [Get the packed size] */
	size_t size;
	error_check(wiredtiger_struct_size(
	    session, &size, "iSh", 42, "hello", -3));
	/*! [Get the packed size] */
	}

	{
	/*! [Pack fields into a buffer] */
	char buf[100];
	error_check(wiredtiger_struct_pack(
	    session, buf, sizeof(buf), "iSh", 42, "hello", -3));
	/*! [Pack fields into a buffer] */

	{
	/*! [Unpack fields from a buffer] */
	int i;
	char *s;
	short h;
	error_check(wiredtiger_struct_unpack(
	    session, buf, sizeof(buf), "iSh", &i, &s, &h));
	/*! [Unpack fields from a buffer] */
	}
	}
}
示例#4
0
int
main(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int i, j, k, ret;

	/*
	 * Create a clean test directory for this run of the test program if the
	 * environment variable isn't already set (as is done by make check).
	 */
	if (getenv("WIREDTIGER_HOME") == NULL) {
		home = "WT_HOME";
		ret = system("rm -rf WT_HOME && mkdir WT_HOME");
	} else
		home = NULL;

	/* Open a connection to the database, creating it if necessary. */
	if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0) {
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home == NULL ? "." : home, wiredtiger_strerror(ret));
		return (EXIT_FAILURE);
	}

	/* Open a session for the current thread's work. */
	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
		fprintf(stderr, "Error opening a session on %s: %s\n",
		    home == NULL ? "." : home, wiredtiger_strerror(ret));
		return (EXIT_FAILURE);
	}

	{
	/*! [packing] */
	size_t size;
	char buf[50];

	ret = wiredtiger_struct_size(session, &size, "iii", 42, 1000, -9);
	if (size > sizeof(buf)) {
		/* Allocate a bigger buffer. */
	}

	ret = wiredtiger_struct_pack(session, buf, size, "iii", 42, 1000, -9);

	ret = wiredtiger_struct_unpack(session, buf, size, "iii", &i, &j, &k);
	/*! [packing] */
	}

	/* Note: closing the connection implicitly closes open session(s). */
	if ((ret = conn->close(conn, NULL)) != 0) {
		fprintf(stderr, "Error closing %s: %s\n",
		    home == NULL ? "." : home, wiredtiger_strerror(ret));
		return (EXIT_FAILURE);
	}

	return (EXIT_SUCCESS);
}
示例#5
0
int main(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	char buf[50];
	size_t size;
	int i, j, k, ret;

	/* Open a connection to the database, creating it if necessary. */
	if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0)
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));

	/* Open a session for the current thread's work. */
	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		fprintf(stderr, "Error opening a session on %s: %s\n",
		    home, wiredtiger_strerror(ret));

	/*! [packing] */
	ret = wiredtiger_struct_size(session, &size, "iii", 42, 1000, -9);
	if (size > sizeof(buf)) {
		/* Allocate a bigger buffer. */
	}

	ret = wiredtiger_struct_pack(session, buf, size, "iii", 42, 1000, -9);

	ret = wiredtiger_struct_unpack(session, buf, size, "iii", &i, &j, &k);
	/*! [packing] */

	/* Note: closing the connection implicitly closes open session(s). */
	if ((ret = conn->close(conn, NULL)) != 0)
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));

	return (ret);
}
示例#6
0
/*
 * A custom index extractor function that adds an index entry for each year of
 * the given president's term.
 */
static int
my_extract(WT_EXTRACTOR *extractor, WT_SESSION *session,
    const WT_ITEM *key, const WT_ITEM *value, WT_CURSOR *result_cursor)
{
	uint16_t term_end, term_start, year;
	char *last_name, *first_name;

	/* Unused parameters */
	(void)extractor;
	(void)key;

	/* Unpack the value. */
	error_check(wiredtiger_struct_unpack(
	    session, value->data, value->size, "SSHH",
	    &last_name, &first_name, &term_start, &term_end));

	/*
	 * We have overlapping years, so multiple records may share the same
	 * index key.
	 */
	for (year = term_start; year <= term_end; ++year) {
		/*
		 * Note that the extract callback is called for all operations
		 * that update the table, not just inserts.  The user sets the
		 * key and uses the cursor->insert() method to return the index
		 * key(s).  WiredTiger will perform the required operation
		 * (such as a remove()).
		 */
		fprintf(stderr,
		    "EXTRACTOR: index op for year %" PRIu16 ": %s %s\n",
		    year, first_name, last_name);
		result_cursor->set_key(result_cursor, year);
		error_check(result_cursor->insert(result_cursor));
	}
	return (0);
}
示例#7
0
int
main(int argc, char *argv[])
{
	POP_RECORD *p;
	WT_CONNECTION *conn;
	WT_CURSOR *country_cursor, *country_cursor2, *cursor, *join_cursor,
	    *stat_cursor, *subjoin_cursor, *year_cursor;
	WT_SESSION *session;
	const char *country;
	uint64_t recno, population;
	uint16_t year;
	int ret;

	home = example_setup(argc, argv);

	error_check(wiredtiger_open(
	    home, NULL, "create,statistics=(fast)", &conn));

	error_check(conn->open_session(conn, NULL, NULL, &session));

	/*! [Create a table with column groups] */
	/*
	 * Create the population table.
	 * Keys are record numbers, the format for values is (5-byte string,
	 * uint16_t, uint64_t).
	 * See ::wiredtiger_struct_pack for details of the format strings.
	 */
	error_check(session->create(session, "table:poptable",
	    "key_format=r,"
	    "value_format=5sHQ,"
	    "columns=(id,country,year,population),"
	    "colgroups=(main,population)"));

	/*
	 * Create two column groups: a primary column group with the country
	 * code, year and population (named "main"), and a population column
	 * group with the population by itself (named "population").
	 */
	error_check(session->create(session,
	    "colgroup:poptable:main", "columns=(country,year,population)"));
	error_check(session->create(session,
	    "colgroup:poptable:population", "columns=(population)"));
	/*! [Create a table with column groups] */

	/*! [Create an index] */
	/* Create an index with a simple key. */
	error_check(session->create(session,
	    "index:poptable:country", "columns=(country)"));
	/*! [Create an index] */

	/*! [Create an index with a composite key] */
	/* Create an index with a composite key (country,year). */
	error_check(session->create(session,
	    "index:poptable:country_plus_year", "columns=(country,year)"));
	/*! [Create an index with a composite key] */

	/*! [Create an immutable index] */
	/* Create an immutable index. */
	error_check(session->create(session,
	    "index:poptable:immutable_year", "columns=(year),immutable"));
	/*! [Create an immutable index] */

	/* Insert the records into the table. */
	error_check(session->open_cursor(
	    session, "table:poptable", NULL, "append", &cursor));
	for (p = pop_data; p->year != 0; p++) {
		cursor->set_value(cursor, p->country, p->year, p->population);
		error_check(cursor->insert(cursor));
	}
	error_check(cursor->close(cursor));

	/* Update records in the table. */
	error_check(session->open_cursor(session,
	    "table:poptable", NULL, NULL, &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		error_check(cursor->get_key(cursor, &recno));
		error_check(cursor->get_value(
		    cursor, &country, &year, &population));
		cursor->set_value(cursor, country, year, population + 1);
		error_check(cursor->update(cursor));
	}
	scan_end_check(ret == WT_NOTFOUND);
	error_check(cursor->close(cursor));

	/* List the records in the table. */
	error_check(session->open_cursor(session,
	    "table:poptable", NULL, NULL, &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		error_check(cursor->get_key(cursor, &recno));
		error_check(cursor->get_value(
		    cursor, &country, &year, &population));
		printf("ID %" PRIu64, recno);
		printf(
		    ": country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	scan_end_check(ret == WT_NOTFOUND);
	error_check(cursor->close(cursor));

	/*! [List the records in the table using raw mode.] */
	/* List the records in the table using raw mode. */
	error_check(session->open_cursor(session,
	    "table:poptable", NULL, "raw", &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		WT_ITEM key, value;

		error_check(cursor->get_key(cursor, &key));
		error_check(wiredtiger_struct_unpack(
		    session, key.data, key.size, "r", &recno));
		printf("ID %" PRIu64, recno);

		error_check(cursor->get_value(cursor, &value));
		error_check(wiredtiger_struct_unpack(session,
		    value.data, value.size,
		    "5sHQ", &country, &year, &population));
		printf(
		    ": country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	scan_end_check(ret == WT_NOTFOUND);
	/*! [List the records in the table using raw mode.] */
	error_check(cursor->close(cursor));

	/*! [Read population from the primary column group] */
	/*
	 * Open a cursor on the main column group, and return the information
	 * for a particular country.
	 */
	error_check(session->open_cursor(
	    session, "colgroup:poptable:main", NULL, NULL, &cursor));
	cursor->set_key(cursor, 2);
	error_check(cursor->search(cursor));
	error_check(cursor->get_value(cursor, &country, &year, &population));
	printf(
	    "ID 2: country %s, year %" PRIu16 ", population %" PRIu64 "\n",
	    country, year, population);
	/*! [Read population from the primary column group] */
	error_check(cursor->close(cursor));

	/*! [Read population from the standalone column group] */
	/*
	 * Open a cursor on the population column group, and return the
	 * population of a particular country.
	 */
	error_check(session->open_cursor(session,
	    "colgroup:poptable:population", NULL, NULL, &cursor));
	cursor->set_key(cursor, 2);
	error_check(cursor->search(cursor));
	error_check(cursor->get_value(cursor, &population));
	printf("ID 2: population %" PRIu64 "\n", population);
	/*! [Read population from the standalone column group] */
	error_check(cursor->close(cursor));

	/*! [Search in a simple index] */
	/* Search in a simple index. */
	error_check(session->open_cursor(session,
	    "index:poptable:country", NULL, NULL, &cursor));
	cursor->set_key(cursor, "AU\0\0\0");
	error_check(cursor->search(cursor));
	error_check(cursor->get_value(cursor, &country, &year, &population));
	printf("AU: country %s, year %" PRIu16 ", population %" PRIu64 "\n",
	    country, year, population);
	/*! [Search in a simple index] */
	error_check(cursor->close(cursor));

	/*! [Search in a composite index] */
	/* Search in a composite index. */
	error_check(session->open_cursor(session,
	    "index:poptable:country_plus_year", NULL, NULL, &cursor));
	cursor->set_key(cursor, "USA\0\0", (uint16_t)1900);
	error_check(cursor->search(cursor));
	error_check(cursor->get_value(cursor, &country, &year, &population));
	printf(
	    "US 1900: country %s, year %" PRIu16 ", population %" PRIu64 "\n",
	    country, year, population);
	/*! [Search in a composite index] */
	error_check(cursor->close(cursor));

	/*! [Return a subset of values from the table] */
	/*
	 * Use a projection to return just the table's country and year
	 * columns.
	 */
	error_check(session->open_cursor(session,
	    "table:poptable(country,year)", NULL, NULL, &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		error_check(cursor->get_value(cursor, &country, &year));
		printf("country %s, year %" PRIu16 "\n", country, year);
	}
	/*! [Return a subset of values from the table] */
	scan_end_check(ret == WT_NOTFOUND);
	error_check(cursor->close(cursor));

	/*! [Return a subset of values from the table using raw mode] */
	/*
	 * Use a projection to return just the table's country and year
	 * columns, using raw mode.
	 */
	error_check(session->open_cursor(session,
	    "table:poptable(country,year)", NULL, "raw", &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		WT_ITEM value;

		error_check(cursor->get_value(cursor, &value));
		error_check(wiredtiger_struct_unpack(
		    session, value.data, value.size, "5sH", &country, &year));
		printf("country %s, year %" PRIu16 "\n", country, year);
	}
	scan_end_check(ret == WT_NOTFOUND);
	/*! [Return a subset of values from the table using raw mode] */
	error_check(cursor->close(cursor));

	/*! [Return the table's record number key using an index] */
	/*
	 * Use a projection to return just the table's record number key
	 * from an index.
	 */
	error_check(session->open_cursor(session,
	    "index:poptable:country_plus_year(id)", NULL, NULL, &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		error_check(cursor->get_key(cursor, &country, &year));
		error_check(cursor->get_value(cursor, &recno));
		printf("row ID %" PRIu64 ": country %s, year %" PRIu16 "\n",
		    recno, country, year);
	}
	scan_end_check(ret == WT_NOTFOUND);
	/*! [Return the table's record number key using an index] */
	error_check(cursor->close(cursor));

	/*! [Return a subset of the value columns from an index] */
	/*
	 * Use a projection to return just the population column from an
	 * index.
	 */
	error_check(session->open_cursor(session,
	    "index:poptable:country_plus_year(population)",
	    NULL, NULL, &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		error_check(cursor->get_key(cursor, &country, &year));
		error_check(cursor->get_value(cursor, &population));
		printf("population %" PRIu64 ": country %s, year %" PRIu16 "\n",
		    population, country, year);
	}
	scan_end_check(ret == WT_NOTFOUND);
	/*! [Return a subset of the value columns from an index] */
	error_check(cursor->close(cursor));

	/*! [Access only the index] */
	/*
	 * Use a projection to avoid accessing any other column groups when
	 * using an index: supply an empty list of value columns.
	 */
	error_check(session->open_cursor(session,
	    "index:poptable:country_plus_year()", NULL, NULL, &cursor));
	while ((ret = cursor->next(cursor)) == 0) {
		error_check(cursor->get_key(cursor, &country, &year));
		printf("country %s, year %" PRIu16 "\n", country, year);
	}
	scan_end_check(ret == WT_NOTFOUND);
	/*! [Access only the index] */
	error_check(cursor->close(cursor));

	/*! [Join cursors] */
	/* Open cursors needed by the join. */
	error_check(session->open_cursor(session,
	    "join:table:poptable", NULL, NULL, &join_cursor));
	error_check(session->open_cursor(session,
	    "index:poptable:country", NULL, NULL, &country_cursor));
	error_check(session->open_cursor(session,
	    "index:poptable:immutable_year", NULL, NULL, &year_cursor));

	/* select values WHERE country == "AU" AND year > 1900 */
	country_cursor->set_key(country_cursor, "AU\0\0\0");
	error_check(country_cursor->search(country_cursor));
	error_check(session->join(
	    session, join_cursor, country_cursor, "compare=eq,count=10"));
	year_cursor->set_key(year_cursor, (uint16_t)1900);
	error_check(year_cursor->search(year_cursor));
	error_check(session->join(session,
	    join_cursor, year_cursor, "compare=gt,count=10,strategy=bloom"));

	/* List the values that are joined */
	while ((ret = join_cursor->next(join_cursor)) == 0) {
		error_check(join_cursor->get_key(join_cursor, &recno));
		error_check(join_cursor->get_value(
		    join_cursor, &country, &year, &population));
		printf("ID %" PRIu64, recno);
		printf(
		    ": country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	scan_end_check(ret == WT_NOTFOUND);
	/*! [Join cursors] */

	/*! [Statistics cursor join cursor] */
	error_check(session->open_cursor(session,
	    "statistics:join",
	    join_cursor, NULL, &stat_cursor));
	/*! [Statistics cursor join cursor] */

	error_check(stat_cursor->close(stat_cursor));
	error_check(join_cursor->close(join_cursor));
	error_check(year_cursor->close(year_cursor));
	error_check(country_cursor->close(country_cursor));

	/*! [Complex join cursors] */
	/* Open cursors needed by the join. */
	error_check(session->open_cursor(session,
	    "join:table:poptable", NULL, NULL, &join_cursor));
	error_check(session->open_cursor(session,
	    "join:table:poptable", NULL, NULL, &subjoin_cursor));
	error_check(session->open_cursor(session,
	    "index:poptable:country", NULL, NULL, &country_cursor));
	error_check(session->open_cursor(session,
	    "index:poptable:country", NULL, NULL, &country_cursor2));
	error_check(session->open_cursor(session,
	    "index:poptable:immutable_year", NULL, NULL, &year_cursor));

	/*
	 * select values WHERE (country == "AU" OR country == "UK")
	 *                     AND year > 1900
	 *
	 * First, set up the join representing the country clause.
	 */
	country_cursor->set_key(country_cursor, "AU\0\0\0");
	error_check(country_cursor->search(country_cursor));
	error_check(session->join(session, subjoin_cursor,
	    country_cursor, "operation=or,compare=eq,count=10"));
	country_cursor2->set_key(country_cursor2, "UK\0\0\0");
	error_check(country_cursor2->search(country_cursor2));
	error_check(session->join(session, subjoin_cursor,
	    country_cursor2, "operation=or,compare=eq,count=10"));

	/* Join that to the top join, and add the year clause */
	error_check(session->join(session, join_cursor, subjoin_cursor, NULL));
	year_cursor->set_key(year_cursor, (uint16_t)1900);
	error_check(year_cursor->search(year_cursor));
	error_check(session->join(session,
	    join_cursor, year_cursor, "compare=gt,count=10,strategy=bloom"));

	/* List the values that are joined */
	while ((ret = join_cursor->next(join_cursor)) == 0) {
		error_check(join_cursor->get_key(join_cursor, &recno));
		error_check(join_cursor->get_value(
		    join_cursor, &country, &year, &population));
		printf("ID %" PRIu64, recno);
		printf(
		    ": country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	scan_end_check(ret == WT_NOTFOUND);
	/*! [Complex join cursors] */

	error_check(join_cursor->close(join_cursor));
	error_check(subjoin_cursor->close(subjoin_cursor));
	error_check(country_cursor->close(country_cursor));
	error_check(country_cursor2->close(country_cursor2));
	error_check(year_cursor->close(year_cursor));

	error_check(conn->close(conn, NULL));

	return (EXIT_SUCCESS);
}
示例#8
0
文件: ex_schema.c 项目: Asamaha/mongo
int
main(void)
{
	POP_RECORD *p;
	WT_CONNECTION *conn;
	WT_CURSOR *cursor, *cursor2, *join_cursor, *stat_cursor;
	WT_SESSION *session;
	const char *country;
	uint64_t recno, population;
	uint16_t year;
	int ret;

	/*
	 * Create a clean test directory for this run of the test program if the
	 * environment variable isn't already set (as is done by make check).
	 */
	if (getenv("WIREDTIGER_HOME") == NULL) {
		home = "WT_HOME";
		ret = system("rm -rf WT_HOME && mkdir WT_HOME");
	} else
		home = NULL;

	if ((ret = wiredtiger_open(
	    home, NULL, "create,statistics=(fast)", &conn)) != 0) {
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));
		return (ret);
	}
	/* Note: error checking omitted for clarity. */

	ret = conn->open_session(conn, NULL, NULL, &session);

	/*! [Create a table with column groups] */
	/*
	 * Create the population table.
	 * Keys are record numbers, the format for values is (5-byte string,
	 * uint16_t, uint64_t).
	 * See ::wiredtiger_struct_pack for details of the format strings.
	 */
	ret = session->create(session, "table:poptable",
	    "key_format=r,"
	    "value_format=5sHQ,"
	    "columns=(id,country,year,population),"
	    "colgroups=(main,population)");

	/*
	 * Create two column groups: a primary column group with the country
	 * code, year and population (named "main"), and a population column
	 * group with the population by itself (named "population").
	 */
	ret = session->create(session,
	    "colgroup:poptable:main", "columns=(country,year,population)");
	ret = session->create(session,
	    "colgroup:poptable:population", "columns=(population)");
	/*! [Create a table with column groups] */

	/*! [Create an index] */
	/* Create an index with a simple key. */
	ret = session->create(session,
	    "index:poptable:country", "columns=(country)");
	/*! [Create an index] */

	/*! [Create an index with a composite key] */
	/* Create an index with a composite key (country,year). */
	ret = session->create(session,
	    "index:poptable:country_plus_year", "columns=(country,year)");
	/*! [Create an index with a composite key] */

	/*! [Create an immutable index] */
	/* Create an immutable index. */
	ret = session->create(session,
	    "index:poptable:immutable_year", "columns=(year),immutable");
	/*! [Create an immutable index] */

	/* Insert the records into the table. */
	ret = session->open_cursor(
	    session, "table:poptable", NULL, "append", &cursor);
	for (p = pop_data; p->year != 0; p++) {
		cursor->set_value(cursor, p->country, p->year, p->population);
		ret = cursor->insert(cursor);
	}
	ret = cursor->close(cursor);

	/* Update records in the table. */
	ret = session->open_cursor(session,
	    "table:poptable", NULL, NULL, &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		ret = cursor->get_key(cursor, &recno);
		ret = cursor->get_value(cursor, &country, &year, &population);
		cursor->set_value(cursor, country, year, population + 1);
		ret = cursor->update(cursor);
	}
	ret = cursor->close(cursor);

	/* List the records in the table. */
	ret = session->open_cursor(session,
	    "table:poptable", NULL, NULL, &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		ret = cursor->get_key(cursor, &recno);
		ret = cursor->get_value(cursor, &country, &year, &population);
		printf("ID %" PRIu64, recno);
		printf(
		    ": country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	ret = cursor->close(cursor);

	/*! [List the records in the table using raw mode.] */
	/* List the records in the table using raw mode. */
	ret = session->open_cursor(session,
	    "table:poptable", NULL, "raw", &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		WT_ITEM key, value;

		ret = cursor->get_key(cursor, &key);
		ret = wiredtiger_struct_unpack(session,
		    key.data, key.size, "r", &recno);
		printf("ID %" PRIu64, recno);

		ret = cursor->get_value(cursor, &value);
		ret = wiredtiger_struct_unpack(session,
		    value.data, value.size,
		    "5sHQ", &country, &year, &population);
		printf(
		    ": country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	/*! [List the records in the table using raw mode.] */
	ret = cursor->close(cursor);

	/*! [Read population from the primary column group] */
	/*
	 * Open a cursor on the main column group, and return the information
	 * for a particular country.
	 */
	ret = session->open_cursor(
	    session, "colgroup:poptable:main", NULL, NULL, &cursor);
	cursor->set_key(cursor, 2);
	if ((ret = cursor->search(cursor)) == 0) {
		ret = cursor->get_value(cursor, &country, &year, &population);
		printf(
		    "ID 2: "
		    "country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	/*! [Read population from the primary column group] */
	ret = cursor->close(cursor);

	/*! [Read population from the standalone column group] */
	/*
	 * Open a cursor on the population column group, and return the
	 * population of a particular country.
	 */
	ret = session->open_cursor(session,
	    "colgroup:poptable:population", NULL, NULL, &cursor);
	cursor->set_key(cursor, 2);
	if ((ret = cursor->search(cursor)) == 0) {
		ret = cursor->get_value(cursor, &population);
		printf("ID 2: population %" PRIu64 "\n", population);
	}
	/*! [Read population from the standalone column group] */
	ret = cursor->close(cursor);

	/*! [Search in a simple index] */
	/* Search in a simple index. */
	ret = session->open_cursor(session,
	    "index:poptable:country", NULL, NULL, &cursor);
	cursor->set_key(cursor, "AU\0\0\0");
	ret = cursor->search(cursor);
	ret = cursor->get_value(cursor, &country, &year, &population);
	printf("AU: country %s, year %" PRIu16 ", population %" PRIu64 "\n",
	    country, year, population);
	/*! [Search in a simple index] */
	ret = cursor->close(cursor);

	/*! [Search in a composite index] */
	/* Search in a composite index. */
	ret = session->open_cursor(session,
	    "index:poptable:country_plus_year", NULL, NULL, &cursor);
	cursor->set_key(cursor, "USA\0\0", (uint16_t)1900);
	ret = cursor->search(cursor);
	ret = cursor->get_value(cursor, &country, &year, &population);
	printf(
	    "US 1900: country %s, year %" PRIu16 ", population %" PRIu64 "\n",
	    country, year, population);
	/*! [Search in a composite index] */
	ret = cursor->close(cursor);

	/*! [Return a subset of values from the table] */
	/*
	 * Use a projection to return just the table's country and year
	 * columns.
	 */
	ret = session->open_cursor(session,
	    "table:poptable(country,year)", NULL, NULL, &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		ret = cursor->get_value(cursor, &country, &year);
		printf("country %s, year %" PRIu16 "\n", country, year);
	}
	/*! [Return a subset of values from the table] */
	ret = cursor->close(cursor);

	/*! [Return a subset of values from the table using raw mode] */
	/*
	 * Use a projection to return just the table's country and year
	 * columns, using raw mode.
	 */
	ret = session->open_cursor(session,
	    "table:poptable(country,year)", NULL, "raw", &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		WT_ITEM value;

		ret = cursor->get_value(cursor, &value);
		ret = wiredtiger_struct_unpack(
		    session, value.data, value.size, "5sH", &country, &year);
		printf("country %s, year %" PRIu16 "\n", country, year);
	}
	/*! [Return a subset of values from the table using raw mode] */
	ret = cursor->close(cursor);

	/*! [Return the table's record number key using an index] */
	/*
	 * Use a projection to return just the table's record number key
	 * from an index.
	 */
	ret = session->open_cursor(session,
	    "index:poptable:country_plus_year(id)", NULL, NULL, &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		ret = cursor->get_key(cursor, &country, &year);
		ret = cursor->get_value(cursor, &recno);
		printf("row ID %" PRIu64 ": country %s, year %" PRIu16 "\n",
		    recno, country, year);
	}
	/*! [Return the table's record number key using an index] */
	ret = cursor->close(cursor);

	/*! [Return a subset of the value columns from an index] */
	/*
	 * Use a projection to return just the population column from an
	 * index.
	 */
	ret = session->open_cursor(session,
	    "index:poptable:country_plus_year(population)",
	    NULL, NULL, &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		ret = cursor->get_key(cursor, &country, &year);
		ret = cursor->get_value(cursor, &population);
		printf("population %" PRIu64 ": country %s, year %" PRIu16 "\n",
		    population, country, year);
	}
	/*! [Return a subset of the value columns from an index] */
	ret = cursor->close(cursor);

	/*! [Access only the index] */
	/*
	 * Use a projection to avoid accessing any other column groups when
	 * using an index: supply an empty list of value columns.
	 */
	ret = session->open_cursor(session,
	    "index:poptable:country_plus_year()", NULL, NULL, &cursor);
	while ((ret = cursor->next(cursor)) == 0) {
		ret = cursor->get_key(cursor, &country, &year);
		printf("country %s, year %" PRIu16 "\n", country, year);
	}
	/*! [Access only the index] */
	ret = cursor->close(cursor);

	/*! [Join cursors] */
	/* Open cursors needed by the join. */
	ret = session->open_cursor(session,
	    "join:table:poptable", NULL, NULL, &join_cursor);
	ret = session->open_cursor(session,
	    "index:poptable:country", NULL, NULL, &cursor);
	ret = session->open_cursor(session,
	    "index:poptable:immutable_year", NULL, NULL, &cursor2);

	/* select values WHERE country == "AU" AND year > 1900 */
	cursor->set_key(cursor, "AU\0\0\0");
	ret = cursor->search(cursor);
	ret = session->join(session, join_cursor, cursor,
	    "compare=eq,count=10");
	cursor2->set_key(cursor2, (uint16_t)1900);
	ret = cursor2->search(cursor2);
	ret = session->join(session, join_cursor, cursor2,
	    "compare=gt,count=10,strategy=bloom");

	/* List the values that are joined */
	while ((ret = join_cursor->next(join_cursor)) == 0) {
		ret = join_cursor->get_key(join_cursor, &recno);
		ret = join_cursor->get_value(join_cursor, &country, &year,
		    &population);
		printf("ID %" PRIu64, recno);
		printf(
		    ": country %s, year %" PRIu16 ", population %" PRIu64 "\n",
		    country, year, population);
	}
	/*! [Join cursors] */

	/*! [Statistics cursor join cursor] */
	ret = session->open_cursor(session,
	    "statistics:join",
	    join_cursor, NULL, &stat_cursor);
	/*! [Statistics cursor join cursor] */

	ret = stat_cursor->close(stat_cursor);
	ret = join_cursor->close(join_cursor);
	ret = cursor2->close(cursor2);
	ret = cursor->close(cursor);

	ret = conn->close(conn, NULL);

	return (ret);
}