[groonga-dev,00039] Re: 一時テーブルが作成できない

Back to archive index

morit****@razil***** morit****@razil*****
2009年 4月 15日 (水) 22:53:30 JST


森です。

すみません。。

一時テーブルであることと、**_TINYであることとは実は別なのです。
**_TINY flagの立ったテーブルは内部使用のためのもので、
DB_API経由でユーザが使用することを想定していません。

GRN_OBJ_PERSISTENTが立っていない場合でも、GRN_IO_HASHやGRN_IO_ARRAYが作成されますが、
この時のioは永続化されないので、一時テーブルとしての仕様を満たしているという考えです。

>>> Kouhei Sutou さんは書きました:
> 須藤です。
> 
> GRN_OBJ_PERSISTENTを指定せずにgrn_table_create()でテーブルを
> 作成しても永続テーブルになってしまいます。
> 
> GRN_{ARRAY,HASH}_TINYをGRN_OBJ_TEMPORARYにする方がよい気もし
> ますが、とりあえず、grn_table_create()でごにょごにょするパッ
> チです。
> 
> diff --git a/lib/db.c b/lib/db.c
> index 0c1f05e..6711aee 100644
> --- a/lib/db.c
> +++ b/lib/db.c
> @@ -509,12 +509,16 @@ grn_table_create(grn_ctx *ctx, const char *name, unsigned name_size,
>                  &subrec_offset, &key_size, &value_size);
>    switch (flags & GRN_OBJ_TABLE_TYPE_MASK) {
>    case GRN_OBJ_TABLE_HASH_KEY :
> +    if (!(flags & GRN_OBJ_PERSISTENT))
> +      flags |= GRN_HASH_TINY;
>      res = (grn_obj *)grn_hash_create(ctx, path, key_size, value_size, flags, encoding);
>      break;
>    case GRN_OBJ_TABLE_PAT_KEY :
>      res = (grn_obj *)grn_pat_create(ctx, path, key_size, value_size, flags, encoding);
>      break;
>    case GRN_OBJ_TABLE_NO_KEY :
> +    if (!(flags & GRN_OBJ_PERSISTENT))
> +      flags |= GRN_ARRAY_TINY;
>      res = (grn_obj *)grn_array_create(ctx, path, value_size, flags);
>      break;
>    }
> diff --git a/test/unit/core/test-table.c b/test/unit/core/test-table.c
> index c58786f..19c9374 100644
> --- a/test/unit/core/test-table.c
> +++ b/test/unit/core/test-table.c
> @@ -24,6 +24,8 @@
>  #include "../lib/grn-assertions.h"
>  
>  void test_array_set_data(void);
> +void test_array_create_temporary(void);
> +void test_hash_create_temporary(void);
>  
>  static grn_logger_info *logger;
>  static grn_ctx context;
> @@ -66,3 +68,25 @@ test_array_set_data(void)
>    retrieved_record_value = grn_obj_get_value(&context, table, record_id, NULL);
>    cut_assert_equal_string(value, GRN_BULK_HEAD(retrieved_record_value));
>  }
> +
> +void
> +test_array_create_temporary(void)
> +{
> +  grn_obj *table;
> +
> +  table = grn_table_create(&context, NULL, 0, NULL,
> +                           GRN_OBJ_TABLE_NO_KEY,
> +                           NULL, sizeof(grn_id), GRN_ENC_DEFAULT);
> +  cut_assert_equal_string(NULL, grn_obj_path(&context, table));
> +}
> +
> +void
> +test_hash_create_temporary(void)
> +{
> +  grn_obj *table;
> +
> +  table = grn_table_create(&context, NULL, 0, NULL,
> +                           GRN_OBJ_TABLE_HASH_KEY,
> +                           NULL, sizeof(grn_id), GRN_ENC_DEFAULT);
> +  cut_assert_equal_string(NULL, grn_obj_path(&context, table));
> +}
> 
> --
> 須藤 功平 <kou****@clear*****>
> 
> 株式会社クリアコード (http://www.clear-code.com/)
> 
> _______________________________________________
> groonga-dev mailing list
> groon****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/groonga-dev
> 
--
morita




groonga-dev メーリングリストの案内
Back to archive index