File: logical_select.rst

package info (click to toggle)
groonga 9.0.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,496 kB
  • sloc: ansic: 608,707; ruby: 35,042; xml: 23,643; cpp: 10,319; sh: 7,453; yacc: 5,968; python: 3,033; makefile: 2,609; perl: 133
file content (1550 lines) | stat: -rw-r--r-- 46,734 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
.. -*- rst -*-

.. highlightlang:: none

.. groonga-command
.. database: logical_select

``logical_select``
==================

Summary
-------

.. versionadded:: 5.0.5

``logical_select`` is a sharding version of
:doc:`select`. ``logical_select`` searches records from multiple
tables and outputs them.

You need to :doc:`plugin_register` ``sharding`` plugin because
this command is included in ``sharding`` plugin.

Syntax
------

This command takes many parameters.

The required parameters are ``logical_table`` and ``shard_key``. Other
parameters are optional::

  logical_select logical_table
                 shard_key
                 [min=null]
                 [min_border="include"]
                 [max=null]
                 [max_border="include"]
                 [filter=null]
                 [sortby=null]
                 [output_columns="_id, _key, *"]
                 [offset=0]
                 [limit=10]
                 [drilldown=null]
                 [drilldown_sortby=null]
                 [drilldown_output_columns="_key, _nsubrecs"]
                 [drilldown_offset=0]
                 [drilldown_limit=10]
                 [drilldown_calc_types=NONE]
                 [drilldown_calc_target=null]
                 [sort_keys=null]
                 [drilldown_sort_keys=null]
                 [match_columns=null]
                 [query=null]
                 [drilldown_filter=null]
                 [post_filter=null]
                 [load_table=null]
                 [load_columns=null]
                 [load_values=null]

There are some parameters that can be only used as named
parameters. You can't use these parameters as ordered parameters. You
must specify parameter name.

Here are parameters that can be only used as named parameters:

  * ``cache=no``

This command has the following named parameters for dynamic columns:

   * ``columns[${NAME}].stage=null``
   * ``columns[${NAME}].flags=COLUMN_SCALAR``
   * ``columns[${NAME}].type=null``
   * ``columns[${NAME}].value=null``
   * ``columns[${NAME}].window.sort_keys=null``
   * ``columns[${NAME}].window.group_keys=null``

You can use one or more alphabets, digits, ``_`` for ``${NAME}``. For
example, ``column1`` is a valid ``${NAME}``. This is the same rule as
normal column. See also :ref:`column-create-name`.

Parameters that have the same ``${NAME}`` are grouped.

For example, the following parameters specify one dynamic column:

  * ``--columns[name].stage initial``
  * ``--columns[name].type UInt32``
  * ``--columns[name].value 29``

The following parameters specify two dynamic columns:

  * ``--columns[name1].stage initial``
  * ``--columns[name1].type UInt32``
  * ``--columns[name1].value 29``
  * ``--columns[name2].stage filtered``
  * ``--columns[name2].type Float``
  * ``--columns[name2].value '_score * 0.1'``

This command has the following named parameters for advanced
drilldown:

  * ``drilldowns[${LABEL}].keys=null``
  * ``drilldowns[${LABEL}].sort_keys=null``
  * ``drilldowns[${LABEL}].output_columns="_key, _nsubrecs"``
  * ``drilldowns[${LABEL}].offset=0``
  * ``drilldowns[${LABEL}].limit=10``
  * ``drilldowns[${LABEL}].calc_types=NONE``
  * ``drilldowns[${LABEL}].calc_target=null``
  * ``drilldowns[${LABEL}].filter=null``
  * ``drilldowns[${LABEL}].columns[${NAME}].stage=null``
  * ``drilldowns[${LABEL}].columns[${NAME}].flags=COLUMN_SCALAR``
  * ``drilldowns[${LABEL}].columns[${NAME}].type=null``
  * ``drilldowns[${LABEL}].columns[${NAME}].value=null``
  * ``drilldowns[${LABEL}].columns[${NAME}].window.sort_keys=null``
  * ``drilldowns[${LABEL}].columns[${NAME}].window.group_keys=null``

.. deprecated:: 6.1.4

   ``drilldown[...]`` syntax is deprecated. Use ``drilldowns[...]``
   instead.

.. deprecated:: 6.1.5

   :ref:`logical-select-drilldowns-label-sortby` is deprecated.
   Use :ref:`logical-select-drilldowns-label-sort-keys` instead.

You can use one or more alphabets, digits, ``_`` and ``.`` for
``${LABEL}``. For example, ``parent.sub1`` is a valid ``${LABEL}``.

Parameters that have the same ``${LABEL}`` are grouped.

For example, the following parameters specify one drilldown:

  * ``--drilldowns[label].keys column``
  * ``--drilldowns[label].sort_keys -_nsubrecs``

The following parameters specify two drilldowns:

  * ``--drilldowns[label1].keys column1``
  * ``--drilldowns[label1].sort_keys -_nsubrecs``
  * ``--drilldowns[label2].keys column2``
  * ``--drilldowns[label2].sort_keys _key``

Differences from ``select``
---------------------------

Most of ``logical_select`` features can be used like corresponding
:doc:`select` features. For example, parameter name is same, output
format is same and so on.

But there are some differences from :doc:`select`:

  * ``logical_table`` and ``shard_key`` parameters are required
    instead of ``table`` parameter.
  * ``sort_keys`` isn't supported when multiple shards are used. (Only
    one shard is used, they are supported. There is one exception
    about ``sort_keys`` for multiple shards. When ``shard_keys`` and
    ``sort_keys`` are same, they are supported. See
    :ref:`logical-select-sort-keys` about details)
  * ``_value.${KEY_NAME}`` in ``drilldowns[${LABEL}].sort_keys``
    doesn't work with multiple shards. It works with one
    shard. ``_key`` in ``drilldowns[${LABEL}].sort_keys`` work with
    multiple shards.
  * ``_value.${KEY_NAME}`` in ``drilldowns[${LABEL}].output_columns``
    also doesn't work with multiple shards either. It works with one
    shard.
  * ``match_escalation_threshold`` isn't supported yet.
  * ``query_flags`` isn't supported yet.
  * ``query_expander`` isn't supported yet.
  * ``adjuster`` isn't supported yet.

Usage
-----

Let's learn about usage with examples. This section shows many popular
usages.

You need to register ``sharding`` plugin because this command is
included in ``sharding`` plugin.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/usage_plugin_register.log
.. plugin_register sharding


Here are a schema definition and sample data to show usage.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/usage_setup.log
.. table_create Entries_20150708 TABLE_HASH_KEY ShortText
.. column_create Entries_20150708 created_at COLUMN_SCALAR Time
.. column_create Entries_20150708 content COLUMN_SCALAR Text
.. column_create Entries_20150708 n_likes COLUMN_SCALAR UInt32
.. column_create Entries_20150708 tag COLUMN_SCALAR ShortText
..
.. table_create Entries_20150709 TABLE_HASH_KEY ShortText
.. column_create Entries_20150709 created_at COLUMN_SCALAR Time
.. column_create Entries_20150709 content COLUMN_SCALAR Text
.. column_create Entries_20150709 n_likes COLUMN_SCALAR UInt32
.. column_create Entries_20150709 tag COLUMN_SCALAR ShortText
..
.. table_create Terms TABLE_PAT_KEY ShortText \
..   --default_tokenizer TokenBigram \
..   --normalizer NormalizerAuto
.. column_create Terms entries_key_index_20150708 \
..   COLUMN_INDEX|WITH_POSITION Entries_20150708 _key
.. column_create Terms entries_content_index_20150708 \
..   COLUMN_INDEX|WITH_POSITION Entries_20150708 content
.. column_create Terms entries_key_index_20150709 \
..   COLUMN_INDEX|WITH_POSITION Entries_20150709 _key
.. column_create Terms entries_content_index_20150709 \
..   COLUMN_INDEX|WITH_POSITION Entries_20150709 content
..
.. load --table Entries_20150708
.. [
.. {"_key":       "The first post!",
..  "created_at": "2015/07/08 00:00:00",
..  "content":    "Welcome! This is my first post!",
..  "n_likes":    5,
..  "tag":        "Hello"},
.. {"_key":       "Groonga",
..  "created_at": "2015/07/08 01:00:00",
..  "content":    "I started to use Groonga. It's very fast!",
..  "n_likes":    10,
..  "tag":        "Groonga"},
.. {"_key":       "Mroonga",
..  "created_at": "2015/07/08 02:00:00",
..  "content":    "I also started to use Mroonga. It's also very fast! Really fast!",
..  "n_likes":    15,
..  "tag":        "Groonga"}
.. ]
..
.. load --table Entries_20150709
.. [
.. {"_key":       "Good-bye Senna",
..  "created_at": "2015/07/09 00:00:00",
..  "content":    "I migrated all Senna system!",
..  "n_likes":    3,
..  "tag":        "Senna"},
.. {"_key":       "Good-bye Tritonn",
..  "created_at": "2015/07/09 01:00:00",
..  "content":    "I also migrated all Tritonn system!",
..  "n_likes":    3,
..  "tag":        "Senna"}
.. ]

There are two tables, ``Entries_20150708`` and ``Entries_20150709``,
for blog entries.

.. note::

   You need to use ``${LOGICAL_TABLE_NAME}_${YYYYMMDD}`` naming rule
   for table names. In this example, ``LOGICAL_TABLE_NAME`` is
   ``Entries`` and ``YYYYMMDD`` is ``20150708`` or ``20150709``.

An entry has title, created time, content, the number of likes for the
entry and tag. Title is key of ``Entries_YYYYMMDD``. Created time is
value of ``Entries_YYYYMMDD.created_at`` column. Content is value of
``Entries_YYYYMMDD.content`` column. The number of likes is value of
``Entries_YYYYMMDD.n_likes`` column. Tag is value of
``Entries_YYYYMMDD.tag`` column.

``Entries_YYYYMMDD._key`` column and ``Entries_YYYYMMDD.content``
column are indexed using ``TokenBigram`` tokenizer. So both
``Entries_YYYYMMDD._key`` and ``Entries_YYYYMMDD.content`` are
fulltext search ready.

OK. The schema and data for examples are ready.

Simple usage
^^^^^^^^^^^^

Here is an example that specifies only required parameters.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/logical_table_existent.log
.. logical_select --logical_table Entries --shard_key created_at

It is shown that is searched from Entries_20150708 and Entries_20150709 in above example.

Parameters
----------

This section describes parameters of ``logical_select``.

Required parameters
^^^^^^^^^^^^^^^^^^^

There are required parameters, ``logical_table`` and ``shard_key``.

.. _logical-select-logical-table:

``logical_table``
"""""""""""""""""

Specifies logical table name. It means table name without
``_YYYYMMDD`` postfix. If you use actual table such as
``Entries_20150708``, ``Entries_20150709`` and so on, logical table
name is ``Entries``.

You can show 5 records by specifying ``logical_table`` and
``shard_key`` parameters. They are required parameters.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/logical_table_existent.log
.. logical_select --logical_table Entries --shard_key created_at

If nonexistent table is specified, an error is returned.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/logical_table_nonexistent.log
.. logical_select --logical_table Nonexistent --shard_key created_at

.. _logical-select-shard-key:

``shard_key``
"""""""""""""

Specifies column name which is treated as shared key. Shard key is a
column that stores data that is used for distributing records to
suitable shards.

Shard key must be ``Time`` type for now.

See :ref:`logical-select-logical-table` how to specify ``shard_key``.

Optional parameters
^^^^^^^^^^^^^^^^^^^

There are optional parameters.

.. _logical-select-min:

``min``
"""""""

Specifies the minimum value of ``shard_key`` column. If shard doesn't
have any matched records, the shard isn't searched.

For example, ``min`` is ``"2015/07/09 00:00:00"``, ``Entry_20150708``
isn't searched. Because ``Entry_20150708`` has only records for
``"2015/07/08"``.

The following example only uses ``Entry_20150709``
table. ``Entry_20150708`` isn't used.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/min.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --min "2015/07/09 00:00:00"

.. _logical-select-min-border:

``min_border``
""""""""""""""

Specifies whether the minimum value is included or not. Here is
available values.

.. list-table::
   :header-rows: 1

   * - Value
     - Description
   * - ``include``
     - Includes ``min`` value. This is the default.
   * - ``exclude``
     - Doesn't include ``min`` value.

Here is an example for ``exclude``. The result doesn't include the
``"Good-bye Senna"`` record because its ``created_at`` value is
``"2015/07/09 00:00:00"``.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/min_border.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --min "2015/07/09 00:00:00" \
..   --min_border "exclude"

.. _logical-select-max:

``max``
"""""""

Specifies the maximum value of ``shard_key`` column. If shard doesn't
have any matched records, the shard isn't searched.

For example, ``max`` is ``"2015/07/08 23:59:59"``, ``Entry_20150709``
isn't searched. Because ``Entry_20150709`` has only records for
``""2015/07/09"``.

The following example only uses ``Entry_20150708``
table. ``Entry_20150709`` isn't used.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/max.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --max "2015/07/08 23:59:59"

.. _logical-select-max-border:

``max_border``
""""""""""""""

Specifies whether the maximum value is included or not. Here is
available values.

.. list-table::
   :header-rows: 1

   * - Value
     - Description
   * - ``include``
     - Includes ``max`` value. This is the default.
   * - ``exclude``
     - Doesn't include ``max`` value.

Here is an example for ``exclude``. The result doesn't include the
``"Good-bye Senna"`` record because its ``created_at`` value is
``"2015/07/09 00:00:00"``.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/max_border.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --max "2015/07/09 00:00:00" \
..   --max_border "exclude"

.. _logical-select-search-related-parameters:

Search related parameters
^^^^^^^^^^^^^^^^^^^^^^^^^

This command provides :doc:`select` compatible search related
parameters.

.. _logical-select-match-columns:

``match_columns``
"""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-match-columns` in :doc:`select`. See
:ref:`select-match-columns` for details.

Here is an example to find records that include ``"fast"`` text in
``content`` column:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/match_columns.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --match_columns content \
..   --query "fast"

.. _logical-select-query:

``query``
"""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-query` in :doc:`select`. See
:ref:`select-query` for details.

Here is an example to find records that include ``"fast"`` text in
``content`` column:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/query.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --query "content:@fast"

See also :ref:`logical-select-match-columns`.

.. _logical-select-filter:

``filter``
""""""""""

Corresponds to :ref:`select-filter` in :doc:`select`. See
:ref:`select-filter` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/filter.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --filter "n_likes <= 5"

.. _logical-select-post-filter:

``post_filter``
"""""""""""""""

.. versionadded:: 8.0.1

Specifies the filter text that is processed after ``filtered`` stage
dynamic columns are generated. You can use ``post_filter`` to filter
by ``filtered`` stage dynamic columns. Others are the same as
:ref:`logical-select-filter`.

Here is an example that shows entries only in popular tag. All target
entries have ``system`` or ``use`` words:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/post_filter.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --columns[n_likes_sum_per_tag].stage filtered \
..   --columns[n_likes_sum_per_tag].type UInt32 \
..   --columns[n_likes_sum_per_tag].value 'window_sum(n_likes)' \
..   --columns[n_likes_sum_per_tag].window.group_keys 'tag' \
..   --filter 'content @ "system" || content @ "use"' \
..   --post_filter 'n_likes_sum_per_tag > 10' \
..   --output_columns _key,n_likes,n_likes_sum_per_tag

.. _logical-select-load-table:

``load_table``
""""""""""""""

.. versionadded:: 8.1.1

You can store specified a table a result of ``logical_select`` with ``--load_table``, ``--load-columns`` and ``--load_values`` arguments.
``--load_table`` specifies a table name for storing a result of ``logical_select``.

You must specify a table that already exists.

This argument must use with :ref:`logical-select-load-columns` and :ref:`logical-select-load-values`.

Here is an example that can store ``_id`` and ``timestamp`` that a result of ``logical_select`` in a Logs table specified by ``--load_table``.

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/load_table.log
.. table_create Logs_20150203 TABLE_HASH_KEY ShortText
.. column_create Logs_20150203 timestamp COLUMN_SCALAR Time
.. table_create Logs_20150204 TABLE_HASH_KEY ShortText
.. column_create Logs_20150204 timestamp COLUMN_SCALAR Time
.. 
.. table_create Logs TABLE_HASH_KEY ShortText
.. column_create Logs original_id COLUMN_SCALAR UInt32
.. column_create Logs timestamp_text COLUMN_SCALAR ShortText
.. 
.. load --table Logs_20150203
.. [
.. {
..   "_key": "2015-02-03:1",
..   "timestamp": "2015-02-03 10:49:00"
.. },
.. {
..   "_key": "2015-02-03:2",
..   "timestamp": "2015-02-03 12:49:00"
.. }
.. ]
.. load --table Logs_20150204
.. [
.. {
..   "_key": "2015-02-04:1",
..   "timestamp": "2015-02-04 00:00:00"
.. }
.. ]
.. logical_select \
..   --logical_table Logs \
..   --shard_key timestamp \
..   --load_table Logs \
..   --load_columns "original_id, timestamp_text" \
..   --load_values "_id, timestamp"
.. select --table Logs

.. _logical-select-load-columns:

``load_columns``
""""""""""""""""

.. versionadded:: 8.1.1

Specifies columns of a table that specifying ``--load-table``.
Stores value of columns that specified with :ref:`logical-select-load-values` in columns that specified with this argument.
You must specify columns that already exists.

This argument must use with :ref:`logical-select-load-table` and :ref:`logical-select-load-values`.

See example of ``--load_table`` for how to use this argument.

.. _logical-select-load-values:

``load_values``
"""""""""""""""

.. versionadded:: 8.1.1

Specifies columns of result of ``logical_select``.
Specifies columns for storing values into columns that specified with :ref:`logical-select-load-columns`.
You must specify columns that already exists.

This argument must use with :ref:`logical-select-load-table` and :ref:`logical-select-load-columns`.

See example of ``--load_table`` for how to use this argument.

.. _logical-select-advanced-search-parameters:

Advanced search parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^

``logical_select`` doesn't implement advanced search parameters yet.

.. _logical-select-match-escalation-threshold:

``match_escalation_threshold``
""""""""""""""""""""""""""""""

Not implemented yet.

.. _logical-select-query-flags:

``query_flags``
"""""""""""""""

Not implemented yet.

.. _logical-select-query-expander:

``query_expander``
""""""""""""""""""

Not implemented yet.

Output related parameters
^^^^^^^^^^^^^^^^^^^^^^^^^

.. _logical-select-output-columns:

``output_columns``
""""""""""""""""""

Corresponds to :ref:`select-output-columns` in :doc:`select`. See
:ref:`select-output-columns` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/output_columns.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --output_columns '_key, *'

.. _logical-select-sortby:

``sortby``
""""""""""

.. deprecated:: 6.1.5

   Use :ref:`logical-select-sort-keys` instead.

.. _logical-select-sort-keys:

``sort_keys``
"""""""""""""

Corresponds to :ref:`select-sort-keys` in :doc:`select`. See
:ref:`select-sort-keys` for details.

``sort_keys`` has a limitation. It works only when the number of
search target shards is one. If the number of search target shards is
larger than one, ``sort_keys`` doesn't work.

.. note::

   There is one exception for multiple shards. When the same value is
   specified for ``shard_key`` and ``sort_keys``, they are supported.
   This command processes target shards one by one by ascending
   order. Thus, in this process, magnitude correlation about the value
   of ``shard_key`` is kept among them. This is because ``sort_keys``
   is supported when ``shard_key`` and ``sort_keys`` is same.

Here is an example that uses only one shard:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/sort_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --min "2015/07/08 00:00:00" \
..   --min_border "include" \
..   --max "2015/07/09 00:00:00" \
..   --max_border "exclude" \
..   --sort_keys _key

.. _logical-select-offset:

``offset``
""""""""""

Corresponds to :ref:`select-offset` in :doc:`select`. See
:ref:`select-offset` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/offset.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --offset 2

.. _logical-select-limit:

``limit``
"""""""""

Corresponds to :ref:`select-limit` in :doc:`select`. See
:ref:`select-limit` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/limit.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 2

.. _logical-select-scorer:

``scorer``
""""""""""

Not implemented yet.

.. _logical-select-dynamic-column-related-parameters:

Dynamic column related parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. versionadded:: 7.0.1

All dynamic column related parameters in :doc:`select` are
supported. See :ref:`select-dynamic-column-related-parameters` for
details.

.. _logical-select-columns-name-stage:

``columns[${NAME}].stage``
""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-columns-name-stage` in :doc:`select`. See
:ref:`select-columns-name-stage` for details.

This is a required parameter.

Here is an example that creates ``is_popular`` column at ``initial``
stage. You can use ``is_popular`` in all parameters such as ``filter``
and ``output_columns``:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/columns_name_stage.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --columns[is_popular].stage initial \
..   --columns[is_popular].type Bool \
..   --columns[is_popular].value 'n_likes >= 10' \
..   --filter is_popular \
..   --output_columns _id,is_popular,n_likes

.. _logical-select-columns-name-flags:

``columns[${NAME}].flags``
""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-columns-name-flags` in :doc:`select`. See
:ref:`select-columns-name-flags` for details.

The default value is ``COLUMN_SCALAR``.

Here is an example that creates a vector column by ``COLUMN_VECTOR``
flags. ``plugin_register functions/vector`` is for using
:doc:`/reference/functions/vector_new` function:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/columns_name_flags.log
.. plugin_register functions/vector
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --columns[vector].stage initial \
..   --columns[vector].flags COLUMN_VECTOR \
..   --columns[vector].type UInt32 \
..   --columns[vector].value 'vector_new(1, 2, 3)' \
..   --output_columns _id,vector

.. _logical-select-columns-name-type:

``columns[${NAME}].type``
"""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-columns-name-type` in :doc:`select`. See
:ref:`select-columns-name-type` for details.

This is a required parameter.

Here is an example that creates a ``ShortText`` type column. Stored
value is casted to ``ShortText`` automatically. In this example,
number is casted to ``ShortText``:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/columns_name_type.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --columns[n_likes_string].stage initial \
..   --columns[n_likes_string].type ShortText \
..   --columns[n_likes_string].value n_likes \
..   --output_columns _id,n_likes,n_likes_string

.. _logical-select-columns-name-value:

``columns[${NAME}].value``
""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-columns-name-value` in :doc:`select`. See
:ref:`select-columns-name-value` for details.

You need to specify :doc:`/reference/window_function` as ``value``
value and other window function related parameters when you use window
function. See :ref:`logical-select-window-function-related-parameters`
for details.

This is a required parameter.

Here is an example that creates a new dynamic column that stores the
number of characters of content. This example uses
:doc:`/reference/functions/string_length` function in
``functions/string`` plugin to compute the number of characters in a
string. :doc:`plugin_register` is used to register
``functions/string`` plugin:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/columns_name_value.log
.. plugin_register functions/string
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --columns[content_length].stage initial \
..   --columns[content_length].type UInt32 \
..   --columns[content_length].value 'string_length(content)' \
..   --output_columns _id,content,content_length

.. _logical-select-window-function-related-parameters:

Window function related parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. versionadded:: 7.0.1

All window function related parameters in :doc:`select` are
supported. See :ref:`select-window-function-related-parameters` for
details.

.. note::

   Window function over multiple tables aren't supported yet.

.. _logical-select-columns-name-window-sort-keys:

``columns[${NAME}].window.sort_keys``
"""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-columns-name-window-sort-keys` in
:doc:`select`. See :ref:`select-columns-name-window-sort-keys` for
details.

You must specify :ref:`logical-select-columns-name-window-sort-keys`
or :ref:`logical-select-columns-name-window-group-keys` to use window
function.

Here is an example that computes cumulative sum per
``Entries.tag``. Each group is sorted by ``Entries._key``:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/columns_name_window_sort_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --columns[n_likes_cumulative_sum_per_tag].stage initial \
..   --columns[n_likes_cumulative_sum_per_tag].type UInt32 \
..   --columns[n_likes_cumulative_sum_per_tag].value 'window_sum(n_likes)' \
..   --columns[n_likes_cumulative_sum_per_tag].window.sort_keys _key \
..   --columns[n_likes_cumulative_sum_per_tag].window.group_keys tag \
..   --sort_keys _key \
..   --output_columns tag,_key,n_likes,n_likes_cumulative_sum_per_tag

.. _logical-select-columns-name-window-group-keys:

``columns[${NAME}].window.group_keys``
""""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-columns-name-window-group-keys` in
:doc:`select`. See :ref:`select-columns-name-window-group-keys` for
details.

You must specify :ref:`logical-select-columns-name-window-sort-keys`
or :ref:`logical-select-columns-name-window-group-keys` to use window
function.

Here is an example that computes sum per ``Entries.tag``:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/columns_name_window_group_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --columns[n_likes_sum_per_tag].stage initial \
..   --columns[n_likes_sum_per_tag].type UInt32 \
..   --columns[n_likes_sum_per_tag].value 'window_sum(n_likes)' \
..   --columns[n_likes_sum_per_tag].window.group_keys tag \
..   --sort_keys _key \
..   --output_columns tag,_key,n_likes,n_likes_sum_per_tag

.. _logical-select-drilldown-related-parameters:

Drilldown related parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

All drilldown related parameters in :doc:`select` are supported. See
:ref:`select-drilldown-related-parameters` for details.

.. _logical-select-drilldown:

``drilldown``
"""""""""""""

Corresponds to :ref:`select-drilldown` in :doc:`select`. See
:ref:`select-drilldown` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldown.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --output_columns _key,tag \
..   --drilldown tag

.. _logical-select-drilldown-sortby:

``drilldown_sortby``
""""""""""""""""""""

.. deprecated:: 6.1.5

   Use :ref:`logical-select-drilldown-sort-keys` instead.

.. _logical-select-drilldown-sort-keys:

``drilldown_sort_keys``
"""""""""""""""""""""""

Corresponds to :ref:`select-drilldown-sort-keys` in :doc:`select`. See
:ref:`select-drilldown-sort-keys` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldown_sort_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldown tag \
..   --drilldown_sort_keys -_nsubrecs,_key

.. _logical-select-drilldown-output-columns:

``drilldown_output_columns``
""""""""""""""""""""""""""""

Corresponds to :ref:`select-drilldown-output-columns` in
:doc:`select`. See :ref:`select-drilldown-output-columns` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldown_output_columns.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldown tag \
..   --drilldown_output_columns _key

.. _logical-select-drilldown-offset:

``drilldown_offset``
""""""""""""""""""""

Corresponds to :ref:`select-drilldown-offset` in :doc:`select`. See
:ref:`select-drilldown-offset` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldown_offset.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldown tag \
..   --drilldown_offset 1

.. _logical-select-drilldown-limit:

``drilldown_limit``
"""""""""""""""""""

Corresponds to :ref:`select-drilldown-limit` in :doc:`select`. See
:ref:`select-drilldown-limit` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldown_limit.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldown tag \
..   --drilldown_limit 2

.. _logical-select-drilldown-calc-types:

``drilldown_calc_types``
""""""""""""""""""""""""

Corresponds to :ref:`select-drilldown-calc-types` in
:doc:`select`. See :ref:`select-drilldown-calc-types` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldown_calc_types.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit -1 \
..   --output_columns tag,n_likes \
..   --drilldown tag \
..   --drilldown_calc_types MAX,MIN,SUM,AVG \
..   --drilldown_calc_target n_likes \
..   --drilldown_output_columns _key,_nsubrecs,_max,_min,_sum,_avg

.. _logical-select-drilldown-calc-target:

``drilldown_calc_target``
"""""""""""""""""""""""""

Corresponds to :ref:`select-drilldown-calc-target` in
:doc:`select`. See :ref:`select-drilldown-calc-target` for details.

See also :ref:`logical-select-drilldown-calc-types` for an example.

.. _logical-select-drilldown-filter:

``drilldown_filter``
""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-drilldown-filter` in
:doc:`select`. See :ref:`select-drilldown-filter` for details.

Here is an example to suppress drilled down tags that are occurred
only once:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldown_filter.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldown tag \
..   --drilldown_filter "_nsubrecs > 1" \
..   --drilldown_output_columns _key,_nsubrecs

.. _logical-select-advanced-drilldown-related-parameters:

Advanced drilldown related parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

All advanced drilldown related parameters in :doc:`select` are
supported. See :ref:`select-advanced-drilldown-related-parameters` for
details.

There are some limitations:

  * ``_value.${KEY_NAME}`` in ``drilldowns[${LABEL}].sort_keys``
    doesn't work with multiple shards. It works with one
    shard. ``_key`` in ``drilldowns[${LABEL}].sort_key`` work with
    multiple shards.

.. _logical-select-drilldowns-label-keys:

``drilldowns[${LABEL}].keys``
"""""""""""""""""""""""""""""

Corresponds to :ref:`select-drilldowns-label-keys` in
:doc:`select`. See :ref:`select-drilldowns-label-keys` for details.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag.n_likes].keys tag,n_likes \
..   --drilldowns[tag.n_likes].output_columns _value.tag,_value.n_likes,_nsubrecs

.. _logical-select-drilldowns-label-output-columns:

``drilldowns[${LABEL}].output_columns``
"""""""""""""""""""""""""""""""""""""""

Corresponds to :ref:`select-drilldowns-label-output-columns` in
:doc:`select`. See :ref:`select-drilldowns-label-output-columns` for
details.

``drilldowns[${LABEL}].output_columns`` has a limitation.

``_value.${KEY_NAME}`` in ``drilldowns[${LABEL}].output_columns`` doesn't
work with multiple shards. It works with one shard.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_output_columns.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].output_columns _key,_nsubrecs

.. _logical-select-drilldowns-label-sortby:

``drilldowns[${LABEL}].sortby``
"""""""""""""""""""""""""""""""

.. deprecated:: 6.1.5

   Use :ref:`logical-select-drilldowns-label-sort-keys` instead.

.. _logical-select-drilldowns-label-sort-keys:

``drilldowns[${LABEL}].sort_keys``
""""""""""""""""""""""""""""""""""

Corresponds to :ref:`logical-select-drilldown-sort-keys` in not
labeled drilldown.

``drilldowns[${LABEL}].sort_keys`` has a limitation.

``_value.${KEY_NAME}`` in ``drilldowns[${LABEL}].sort_keys`` doesn't
work with multiple shards. It works with one shard. ``_key`` in
``drilldowns[${LABEL}].sort_keys`` work with multiple shards.

Here is an example that uses ``_value.${KEY_NAME}`` with only one
shard:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_sort_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --min "2015/07/08 00:00:00" \
..   --min_border "include" \
..   --max "2015/07/09 00:00:00" \
..   --max_border "exclude" \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag.n_likes].keys tag,n_likes \
..   --drilldowns[tag.n_likes].output_columns _nsubrecs,_value.n_likes,_value.tag \
..   --drilldowns[tag.n_likes].sort_keys -_nsubrecs,_value.n_likes,_value.tag

.. _logical-select-drilldowns-label-offset:

``drilldowns[${LABEL}].offset``
"""""""""""""""""""""""""""""""

Corresponds to :ref:`logical-select-drilldown-offset` in not labeled
drilldown.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_offset.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag.n_likes].keys tag \
..   --drilldowns[tag.n_likes].offset 1

.. _logical-select-drilldowns-label-limit:

``drilldowns[${LABEL}].limit``
""""""""""""""""""""""""""""""

Corresponds to :ref:`logical-select-drilldown-limit` in not labeled
drilldown.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_limit.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag.n_likes].keys tag \
..   --drilldowns[tag.n_likes].limit 2

.. _logical-select-drilldowns-label-calc-types:

``drilldowns[${LABEL}].calc_types``
"""""""""""""""""""""""""""""""""""

Corresponds to :ref:`logical-select-drilldown-calc-types` in not
labeled drilldown.

Here is an example:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_calc_types.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].calc_types MAX,MIN,SUM,AVG \
..   --drilldowns[tag].calc_target n_likes \
..   --drilldowns[tag].output_columns _key,_nsubrecs,_max,_min,_sum,_avg

.. _logical-select-drilldowns-label-calc-target:

``drilldowns[${LABEL}].calc_target``
""""""""""""""""""""""""""""""""""""

Corresponds to :ref:`logical-select-drilldown-calc-target` in not
labeled drilldown.

See also :ref:`logical-select-drilldowns-label-calc-types`
for an example.

.. _logical-select-drilldowns-label-filter:

``drilldowns[${LABEL}].filter``
"""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`logical-select-drilldown-filter` in not labeled
drilldown.

Here is an example to suppress drilled down tags that are occurred
only once:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_filter.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].filter "_nsubrecs > 1" \
..   --drilldowns[tag].output_columns _key,_nsubrecs

.. _logical-select-drilldowns-label-columns-name-stage:

``drilldowns[${LABEL}].columns[${NAME}].stage``
"""""""""""""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`select-drilldowns-label-columns-name-stage` in
:doc:`select`. See :ref:`select-drilldowns-label-columns-name-stage`
for details.

Here is an example that creates a dynamic column at ``initial``
stage. This example creates a dynamic column that stores whether each
drilled down tag is occurred only once or not:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_columns_name_stage.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].columns[is_popular].stage initial \
..   --drilldowns[tag].columns[is_popular].type Bool \
..   --drilldowns[tag].columns[is_popular].value '_nsubrecs > 1' \
..   --drilldowns[tag].output_columns _key,_nsubrecs,is_popular

.. _logical-select-drilldowns-label-columns-name-flags:

``drilldowns[${LABEL}].columns[${NAME}].flags``
"""""""""""""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`logical-select-columns-name-flags` in main
search.

The default value is ``COLUMN_SCALAR``.

Here is an example that creates a vector column by ``COLUMN_VECTOR``
flags. ``plugin_register functions/vector`` is for using
:doc:`/reference/functions/vector_new` function:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_columns_name_flags.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].columns[vector].stage initial \
..   --drilldowns[tag].columns[vector].flags COLUMN_VECTOR \
..   --drilldowns[tag].columns[vector].type ShortText \
..   --drilldowns[tag].columns[vector].value 'vector_new("a", "b", "c")' \
..   --drilldowns[tag].output_columns _key,vector

.. _logical-select-drilldowns-label-columns-name-type:

``drilldowns[${LABEL}].columns[${NAME}].type``
""""""""""""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`logical-select-columns-name-type` in main
search.

This is a required parameter.

Here is an example that creates a ``ShortText`` type column. Stored
value is casted to ``ShortText`` automatically. In this example,
number is casted to ``ShortText``:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_columns_name_type.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].columns[nsubrecs_string].stage initial \
..   --drilldowns[tag].columns[nsubrecs_string].type ShortText \
..   --drilldowns[tag].columns[nsubrecs_string].value _nsubrecs \
..   --drilldowns[tag].output_columns _key,_nsubrecs,nsubrecs_string

.. _logical-select-drilldowns-label-columns-name-value:

``drilldowns[${LABEL}].columns[${NAME}].value``
"""""""""""""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`logical-select-columns-name-value` in main
search.

This is a required parameter.

Here is an example that creates a new dynamic column that stores the
number of characters of content. This example uses
:doc:`/reference/functions/string_length` function in
``functions/string`` plugin to compute the number of characters in a
string. :doc:`plugin_register` is used to register
``functions/string`` plugin:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_columns_name_value.log
.. plugin_register functions/string \
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].columns[tag_length].stage initial \
..   --drilldowns[tag].columns[tag_length].type UInt32 \
..   --drilldowns[tag].columns[tag_length].value 'string_length(_key)' \
..   --drilldowns[tag].output_columns _key,tag_length

.. _logical-select-drilldowns-label-columns-name-window-sort-keys:

``drilldowns[${LABEL}].columns[${NAME}].window.sort_keys``
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`logical-select-columns-name-window-sort-keys` in
main search.

You must specify
:ref:`logical-select-drilldowns-label-columns-name-window-sort-keys`
or
:ref:`logical-select-drilldowns-label-columns-name-window-group-keys`
to use window function.

Here is an example that computes the Nth record in the number of sub
records order:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_columns_name_window_sort_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].columns[record_number].stage initial \
..   --drilldowns[tag].columns[record_number].type UInt32 \
..   --drilldowns[tag].columns[record_number].value 'window_record_number()' \
..   --drilldowns[tag].columns[record_number].window.sort_keys _nsubrecs,_key \
..   --drilldowns[tag].sort_keys record_number \
..   --drilldowns[tag].output_columns _key,_nsubrecs,record_number

.. _logical-select-drilldowns-label-columns-name-window-group-keys:

``drilldowns[${LABEL}].columns[${NAME}].window.group_keys``
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. versionadded:: 7.0.1

Corresponds to :ref:`logical-select-columns-name-window-group-keys` in
main search.

You must specify
:ref:`logical-select-drilldowns-label-columns-name-window-sort-keys`
or
:ref:`logical-select-drilldowns-label-columns-name-window-group-keys`
to use window function.

Here is an example that computes the Nth record ordered by tag name
for each the same number of sub records:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/drilldowns_label_columns_name_window_group_keys.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --limit 0 \
..   --output_columns _id \
..   --drilldowns[tag].keys tag \
..   --drilldowns[tag].columns[record_number].stage initial \
..   --drilldowns[tag].columns[record_number].type UInt32 \
..   --drilldowns[tag].columns[record_number].value 'window_record_number()' \
..   --drilldowns[tag].columns[record_number].window.sort_keys _key \
..   --drilldowns[tag].columns[record_number].window.group_keys _nsubrecs \
..   --drilldowns[tag].sort_keys _nsubrecs,record_number \
..   --drilldowns[tag].output_columns _key,_nsubrecs,record_number

Cache related parameter
^^^^^^^^^^^^^^^^^^^^^^^

.. _logical-select-cache:

``cache``
"""""""""

Specifies whether caching the result of this query or not.

If the result of this query is cached, the next same query returns
response quickly by using the cache.

It doesn't control whether existing cached result is used or not.

Here are available values:

.. list-table::
   :header-rows: 1

   * - Value
     - Description
   * - ``no``
     - Don't cache the output of this query.
   * - ``yes``
     - Cache the output of this query.
       It's the default value.

Here is an example to disable caching the result of this query:

.. groonga-command
.. include:: ../../example/reference/commands/logical_select/cache_no.log
.. logical_select \
..   --logical_table Entries \
..   --shard_key created_at \
..   --cache no

The default value is ``yes``.

Return value
------------

The return value format of ``logical_select`` is compatible with
:doc:`select`. See :ref:`select-return-value` for details.