@@ -54,6 +54,7 @@ const struct index_opts index_opts_default = {
5454 /* .hint = */ INDEX_HINT_DEFAULT ,
5555 /* .covered_fields = */ NULL ,
5656 /* .covered_field_count = */ 0 ,
57+ /* .layout = */ NULL ,
5758};
5859
5960/**
@@ -113,6 +114,24 @@ index_opts_parse_covered_fields(const char **data, void *opts,
113114 return 0 ;
114115}
115116
117+ /** Parse index layout option given as MsgPack in `data' into `opts'. */
118+ static int
119+ index_opts_parse_layout (const char * * data , void * opts , struct region * region )
120+ {
121+ struct index_opts * index_opts = (struct index_opts * )opts ;
122+ if (mp_typeof (* * data ) != MP_STR ) {
123+ diag_set (IllegalParams , "'layout' must be string" );
124+ return -1 ;
125+ }
126+ uint32_t len = 0 ;
127+ const char * str = mp_decode_str (data , & len );
128+ if (len > 0 ) {
129+ index_opts -> layout = xregion_alloc (region , len + 1 );
130+ strlcpy (index_opts -> layout , str , len + 1 );
131+ }
132+ return 0 ;
133+ }
134+
116135const struct opt_def index_opts_reg [] = {
117136 OPT_DEF ("unique" , OPT_BOOL , struct index_opts , is_unique ),
118137 OPT_DEF ("dimension" , OPT_INT64 , struct index_opts , dimension ),
@@ -128,6 +147,7 @@ const struct opt_def index_opts_reg[] = {
128147 OPT_DEF_LEGACY ("sql" ),
129148 OPT_DEF_CUSTOM ("hint" , index_opts_parse_hint ),
130149 OPT_DEF_CUSTOM ("covers" , index_opts_parse_covered_fields ),
150+ OPT_DEF_CUSTOM ("layout" , index_opts_parse_layout ),
131151 OPT_END ,
132152};
133153
@@ -144,6 +164,9 @@ const struct opt_def index_opts_reg[] = {
144164static void
145165index_opts_normalize (struct index_opts * opts , const struct key_def * cmp_def )
146166{
167+ if (opts -> layout != NULL )
168+ opts -> layout = xstrdup (opts -> layout );
169+
147170 if (opts -> covered_field_count == 0 )
148171 return ;
149172 uint32_t * fields = xmalloc (sizeof (* fields ) * opts -> covered_field_count );
@@ -213,6 +236,8 @@ index_opts_dup(const struct index_opts *opts, struct index_opts *dup)
213236 dup -> covered_field_count *
214237 sizeof (* dup -> covered_fields ));
215238 }
239+ if (dup -> layout != NULL )
240+ dup -> layout = xstrdup (dup -> layout );
216241}
217242
218243struct index_def *
@@ -235,7 +260,6 @@ index_def_dup(const struct index_def *def)
235260void
236261index_def_delete (struct index_def * index_def )
237262{
238- free (index_def -> opts .covered_fields );
239263 index_opts_destroy (& index_def -> opts );
240264 free (index_def -> name );
241265 free (index_def -> space_name );
0 commit comments