Need help with converting this df to exact JSON as an example using R. Already tried a lot of approaches but cant succeed. Please help.
Code for generating sample:
df <- data.frame(month = c(1, 1, 1, 2, 2, 2),
station = c('AE', 'DС', 'CL', 'AE', 'DC', 'CL'),
persons = c(3, 12, 21, 12, 10, 9),
results = c(10, 34, 57, 19, 16, 5)
)
Its needed to drop column "station" and add level "summary" which gather results to pairs "person" and "results" just as like example shows.
Needed JSON output.
[
{
"month": "1",
"summary": [
{
"persons": 3,
"results": 10
},
{
"persons": 12,
"results": 34
},
{
"persons": 21,
"results": 57
}
]
},
{
"month": "2",
"summary": [
{
"persons": 12,
"results": 19
},
{
"persons": 10,
"results": 16
},
{
"persons": 9,
"results": 5
}
]
}
]
You could use tidyr::nest and jsonlite::toJson like so:
library(tidyr)
library(dplyr)
library(jsonslite)
df |>
select(-station) |>
group_by(month) |>
nest() |>
rename(summary = data) |>
jsonlite::toJSON()
#> [{"month":1,"summary":[{"persons":3,"results":10},{"persons":12,"results":34},{"persons":21,"results":57}]},{"month":2,"summary":[{"persons":12,"results":19},{"persons":10,"results":16},{"persons":9,"results":5}]}]
I have this json
{
"objectEntries": [
{
"objectType": {
"name": "Test"
},
"attributes": [
{
"id": 16,
"objectTypeAttributeId": 8,
"objectAttributeValues": [
{
"referencedObject": {
"id": 17,
"label": "TestTest",
"attributes": [
{
"id": 20,
"objectTypeAttributeId": 11,
"objectAttributeValues": [
{
"value": "bli"
}
],
"objectId": 12
},
{
"id": 21,
"objectTypeAttributeId": 13,
"objectAttributeValues": [
{
"value": "blo"
}
],
"objectId": 14
},
{
"id": 22,
"objectTypeAttributeId": 15,
"objectAttributeValues": [
{
"referencedObject": {
"id": 30,
"label": "TestTest",
"attributes": [
{
"id": 35,
"objectTypeAttributeId": 36,
"objectAttributeValues": [
{
"value": "bli"
}
],
"objectId": 37
},
{
"id": 38,
"objectTypeAttributeId": 39,
"objectAttributeValues": [
{
"value": "blo"
}
],
"objectId": 40
}
]
}
}
],
"objectId": 16
}
]
}
}
]
},
{
"id": 16,
"objectTypeAttributeId": 8,
"objectAttributeValues": [
{
"referencedObject": {
"id": 17,
"label": "TestTest",
"attributes": [
{
"id": 20,
"objectTypeAttributeId": 11,
"objectAttributeValues": [
{
"value": "bli"
}
],
"objectId": 12
},
{
"id": 21,
"objectTypeAttributeId": 13,
"objectAttributeValues": [
{
"value": "blo"
}
],
"objectId": 14
},
{
"id": 22,
"objectTypeAttributeId": 15,
"objectAttributeValues": [
{
"referencedObject": {
"id": 30,
"label": "TestTest",
"attributes": [
{
"id": 35,
"objectTypeAttributeId": 36,
"objectAttributeValues": [
{
"value": "xxx"
}
],
"objectId": 37
},
{
"id": 38,
"objectTypeAttributeId": 39,
"objectAttributeValues": [
{
"value": "yyy"
}
],
"objectId": 40
}
]
}
}
],
"objectId": 16
}
]
}
}
]
}
]
}
]
}
I want this result.
{
"name": "Test",
"attribute36": "bli",
"attribute39": "blo"
}
{
"name": "Test",
"attribute36": "xxx",
"attribute39": "yyy"
}
But what I get is this
{
"name": "Test",
"attribute36": "bli",
"attribute39": "blo"
}
{
"name": "Test",
"attribute36": "bli",
"attribute39": "yyy"
}
{
"name": "Test",
"attribute36": "xxx",
"attribute39": "blo"
}
{
"name": "Test",
"attribute36": "xxx",
"attribute39": "yyy"
}
The jq query I came up with
jq '.objectEntries[] | {"name": .objectType.name, "attribute36": .attributes | .[] | select(.objectTypeAttributeId==8) | .objectAttributeValues[].referencedObject.attributes | .[] | select(.objectTypeAttributeId==15) | .objectAttributeValues[].referencedObject.attributes | .[] | select(.objectTypeAttributeId==36) | .objectAttributeValues | .[] | .value, "attribute39": .attributes | .[] | select(.objectTypeAttributeId==8) | .objectAttributeValues[].referencedObject.attributes | .[] | select(.objectTypeAttributeId==15) | .objectAttributeValues[].referencedObject.attributes | .[] | select(.objectTypeAttributeId==39) | .objectAttributeValues | .[] | .value}' stackoverflow.json
You can see the problem also on jqplay https://jqplay.org/s/NjqEy7wvQE
The goal is to extract certain fields on the different jsonpath depths into a new, flat json object, per toplevel json object, where toplevel are the objects under objectEntries[]
Looking at the jq query in the Q, we can define two useful functions:
def attributes:
[ .attributes[]
| select(.objectTypeAttributeId==8)
| .objectAttributeValues[].referencedObject.attributes[]
| select(.objectTypeAttributeId==15)
| .objectAttributeValues[].referencedObject.attributes[] ] ;
def to_o:
{ ("attribute" + (.objectTypeAttributeId|tostring)): first(.objectAttributeValues[].value)};
And we see that
.objectEntries[] | attributes[] | to_o
yields:
{"attribute36":"bli"}
{"attribute39":"blo"}
{"attribute36":"xxx"}
{"attribute39":"yyy"}
This is where the original question becomes a bit difficult to understand. I'm going to assume the intent is to group these objects together without loss of information and without introducing arrays.
At any rate, the following filter does produce the desired result:
.objectEntries[]
| .objectType.name as $name
| foreach ((attributes[] | to_o), null ) as $o ({};
if $o == null then .emit = .object
elif .object|has($o|keys_unsorted[0])
then .emit=.object | .object=$o
else .emit=null | .object += $o
end;
select(.emit) | .emit)
| {$name} + .
I need to convert a dataframe to JSON. There are several nested dataframes as variables in the dataframe to convert to JSON.
But, when converting to JSON, I need the data for Values1 described below to be an object (enclosed in {} only) instead of an array (enclosed in []).
The code below is a reprex to show my current workflow and problem.
library(dplyr)
library(tidyr)
library(jsonlite)
df1 <- data.frame(name = c("a", "b", "c"),
v = c(1, 2, 3),
w = c(10, 20, 30)) %>%
group_by(name) %>%
nest_legacy(.key = "Values1")
df2 <- data.frame(name = c("a", "b", "c"),
x = c(5, 10, 15),
y = c(100, 200, 300),
z = c(1000, 2000, 3000)) %>%
group_by(name) %>%
nest_legacy(.key = "Values2")
df3 <- df1 %>%
left_join(df2)
json <- toJSON(df3, dataframe = "rows", pretty = TRUE)
json
This is what the json from the above looks like:
> json
[
{
"name": "a",
"Values1": [
{
"v": 1,
"w": 10
}
],
"Values2": [
{
"x": 5,
"y": 100,
"z": 1000
}
]
},
{
"name": "b",
"Values1": [
{
"v": 2,
"w": 20
}
],
"Values2": [
{
"x": 10,
"y": 200,
"z": 2000
}
]
},
{
"name": "c",
"Values1": [
{
"v": 3,
"w": 30
}
],
"Values2": [
{
"x": 15,
"y": 300,
"z": 3000
}
]
}
]
But, this is what I need it to look like:
> json
[
{
"name": "a",
"Values1": {
"v": 1,
"w": 10
},
"Values2": [
{
"x": 5,
"y": 100,
"z": 1000
}
]
},
{
"name": "b",
"Values1": {
"v": 2,
"w": 20
},
"Values2": [
{
"x": 10,
"y": 200,
"z": 2000
}
]
},
{
"name": "c",
"Values1": {
"v": 3,
"w": 30
},
"Values2": [
{
"x": 15,
"y": 300,
"z": 3000
}
]
}
]
Any ideas how to convert Values1 from arrays to objects? They cannot be in arrays as the API does not accept the [.
I have looked at using unbox() from jsonlite but this only works on singletons. I have also tried to construct my final dataframe in various ways.
Any tips/ideas greatly appreciated!
This should return what you desire:
...
df3 <- left_join(df1, df2, by = "name")
json <- mutate(df3, Values1 = purrr::map(Values1, as.list)) %>%
jsonlite::toJSON(auto_unbox = TRUE, pretty = TRUE)
Can you confirm?
I have a field group named 'Sales Item' and 'Invoice'. The invoice field group have a 'Items' field which is a repeater field, the 'Items' field contains the 'Sales Item' field group as clone field.
I need to create an Invoice post type programmatically. All the field of the 'Invoice' is created except the 'Items' field. How do I add the data to the 'Items' reaper field which contain the 'Sales Item' clone field?
Sales Item and Invoice field group.
[
{
"key": "group_5c4033565a799",
"title": "Invoice",
"fields": [
{
"key": "field_5c44150d123de",
"label": "Type",
"name": "ims_invoice_type",
"type": "select",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"sales": "Sales",
"purchases": "Purchases"
},
"default_value": [
"purchases"
],
"allow_null": 0,
"multiple": 0,
"ui": 0,
"return_format": "value",
"ajax": 0,
"placeholder": ""
},
{
"key": "field_5c4033c40bce3",
"label": "Invoice Number",
"name": "ims_invoice_invoice_number",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_5c4e943170485",
"label": "Customer",
"name": "ims_invoice_customer",
"type": "relationship",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "sales"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"ims_customer"
],
"taxonomy": "",
"filters": [
"search",
"post_type",
"taxonomy"
],
"elements": "",
"min": 1,
"max": 1,
"return_format": "object"
},
{
"key": "field_5c4033620bce1",
"label": "Vendor",
"name": "ims_invoice_vendor",
"type": "relationship",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "purchases"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"ims_vendor"
],
"taxonomy": "",
"filters": [
"search",
"post_type",
"taxonomy"
],
"elements": "",
"min": 1,
"max": 1,
"return_format": "object"
},
{
"key": "field_5c40339b0bce2",
"label": "Date",
"name": "ims_invoice_date",
"type": "date_picker",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"display_format": "F j, Y",
"return_format": "d\/m\/Y",
"first_day": 0
},
{
"key": "field_5c4034030cff9",
"label": "Items",
"name": "ims_invoice_sales_items",
"type": "repeater",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "sales"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 0,
"max": 0,
"layout": "table",
"button_label": "Add Product",
"sub_fields": [
{
"key": "field_5c443f4dd87de",
"label": "Item",
"name": "ims_invoice_sales_items",
"type": "clone",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"clone": [
"group_5c443e86ad330"
],
"display": "seamless",
"layout": "block",
"prefix_label": 0,
"prefix_name": 1
}
]
},
{
"key": "field_5c78f715c5efe",
"label": "Items",
"name": "ims_invoice_purchases_items",
"type": "repeater",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "purchases"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 0,
"max": 0,
"layout": "table",
"button_label": "Add Product",
"sub_fields": [
{
"key": "field_5c78f730c5eff",
"label": "Items",
"name": "ims_invoice_purchases_items",
"type": "clone",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"clone": [
"group_5c78e0e32443c"
],
"display": "seamless",
"layout": "block",
"prefix_label": 0,
"prefix_name": 1
}
]
},
{
"key": "field_5c41b2ff17b09",
"label": "Sub Total",
"name": "ims_invoice_sub_total",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c41b31a17b0b",
"label": "Discount",
"name": "ims_invoice_discount",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": 0,
"max": "",
"step": ""
},
{
"key": "field_5c41b32617b0c",
"label": "V.A.T",
"name": "ims_invoice_vat",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": 0,
"max": "",
"step": ""
},
{
"key": "field_5c41b33317b0d",
"label": "Total",
"name": "ims_invoice_total",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c41b33b17b0e",
"label": "Paid",
"name": "ims_invoice_paid",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": 0,
"max": "",
"step": ""
},
{
"key": "field_5c41b34517b0f",
"label": "Due",
"name": "ims_invoice_due",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "ims_invoice"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "left",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
},
{
"key": "group_5c443e86ad330",
"title": "Sales Item",
"fields": [
{
"key": "field_5c443eab22fe1",
"label": "Item",
"name": "sales_item_item",
"type": "post_object",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"ims_product"
],
"taxonomy": "",
"allow_null": 0,
"multiple": 0,
"return_format": "object",
"ui": 1
},
{
"key": "field_5c779ac395834",
"label": "SKU",
"name": "sales_item_sku",
"type": "read_only",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c443eba22fe2",
"label": "Quantity",
"name": "sales_item_quantity",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": 1,
"placeholder": "",
"prepend": "",
"append": "",
"min": "",
"max": "",
"step": ""
},
{
"key": "field_5c443ec622fe3",
"label": "Unit Price",
"name": "sales_item_unit_price",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c443edf22fe4",
"label": "Price",
"name": "sales_item_price",
"type": "read_only",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c443efd22fe5",
"label": "Discount",
"name": "sales_item_discount",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": "",
"max": "",
"step": ""
},
{
"key": "field_5c443f0a22fe6",
"label": "Amount",
"name": "sales_item_amount",
"type": "read_only",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "post"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 0,
"description": ""
}
]
Here is the code, I have written so far.
$invoice_key = 'ims_invoice_sales_items_';
$customer_id = $_POST['customer_id'];
$ims_products = $_POST['ims_product'];
$basket_discount = $_POST['basket_discount'];
$basket_vat = $_POST['basket_vat'];
$paid = $_POST['paid'];
$sub_total = 0.0;
foreach( $ims_products as $ims_product ) {
$id = $ims_product['id'];
$quantity = intval( $ims_product['quantity'] );
$unit_price = floatval( get_field( 'ims_product_mrp', $id ) );
$discount = floatval( $ims_product['discount'] );
$price = $quantity * $unit_price;
$amount = $price - ( $discount * $price ) / 100.0;
$sub_total += $amount;
$items [] = array(
$invoice_key . 'sales_item_item' => $id,
$invoice_key . 'sales_item_sku' => get_field( 'ims_product_sku', $id ),
$invoice_key . 'sales_item_quantity' => $quantity,
$invoice_key . 'sales_item_unit_price' => $unit_price,
$invoice_key . 'sales_item_price' => $price,
$invoice_key . 'sales_item_discount' => $discount,
$invoice_key . 'sales_item_amount' => $amount
);
}
// var_dump( $items );
// Calculate grand total after discount and vat.
$grand_total = $sub_total - ( $basket_discount * $sub_total ) / 100.0;
$grand_total = $grand_total + ( $basket_vat * $grand_total ) / 100.0;
// Calculate due.
$due = $grand_total - $paid;
$meta_inputs = array(
'ims_invoice_type' => 'sales',
'ims_invoice_invoice_number' => uniqid(),
'ims_invoice_customer' => $customer_id,
'ims_invoice_date' => current_time('d/m/Y', false ),
'ims_invoice_sub_total' => $sub_total,
'ims_invoice_discount' => $basket_discount,
'ims_invoice_vat' => $basket_vat,
'ims_invoice_total' => $grand_total,
'ims_invoice_paid' => $paid,
'ims_invoice_due' => $due
);
$invoice_args = array(
'post_type' => 'ims_invoice',
'post_status' => 'publish',
'meta_input' => $meta_inputs
);
// var_dump( $invoice_args );
$post_id = wp_insert_post( $invoice_args, true );
var_dump( "<h1>Post Id = ${post_id}</h1>");
foreach( $items as $item ) {
var_dump( $item );
add_row( 'ims_invoice_sales_items', $item, $post_id );
}
die;
You don't actually need to call add_row and add each repeater entry in sequence. You can push the entire items array in one go. You will need to do following things to make sure that the below conditions are met and the code will work for you.
You have the correct field key for your repeater field (Something to the effect of field_5bfed0e63a470).
The slug of each repeating element in the repeater group is correct(For example repeater group has a field sales item and the slug for it is in the format sales_item_item).
Once You have made sure of that you just need to create an array of the new items set as you have already created with $items variable and call the below code:
$items_inserted = update_field('field_5bfed0e63a470', $items, $post_id);
Things should work fine for you with this. Good Luck!!!
I'm trying to optimize some queries in MariaDB, and I've found the ANALYZE FORMAT=JSON functionality to be extremely useful. However, in the case of some complex joins, I'm running into some examples where the time doesn't add up, or come close to it.
A when-it-works example, in the case of one query, the query_block r_total_time_ms was about 239ms; the query itself involved 11 tables, and one of those 11 was taking up nearly 227ms, accounting for the large majority of the time spent in the query. There was an obvious index change to make, and making it took that element down to less than 1 ms, and total query time to just over 1 ms.
But in another case, the query_block r_total_time_ms is a little over 163ms; the query involves 9 tables and/or subqueries, and the highest r_total_time_ms for any of the components is just over 15 ms. The total of all those components adds up to about 25 ms. So where is the rest of the time being spent? What's it doing for the other 140-ish ms? If there's a way to tell, I don't know what it is.
Here's the ANALYZE output that I'm struggling with:
ANALYZE
{
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": 163.18,
"filesort": {
"sort_key": "tcontent.lastUpdate",
"r_loops": 1,
"r_total_time_ms": 0.0147,
"r_limit": 20,
"r_used_priority_queue": false,
"r_output_rows": 2,
"r_buffer_size": "252",
"temporary_table": {
"table": {
"table_name": "tcontent",
"access_type": "index_merge",
"possible_keys": [
"IX_TContent",
"IX_TContent_1",
"IX_TContent_2",
"IX_TContent_5",
"IX_tcontent_mobileExclude",
"IX_tcontent_displaystart",
"IX_tcontent_displaystop",
"IX_tcontent_approved",
"IX_tcontent_active",
"IX_tcontent_display",
"IX_tcontent_type",
"ntID_Type_subType_Display_DisplayStart_DisplayStop_mobileExclude",
"ix_tcontent_SiteID_Active_Filename_Type"
],
"key_length": "2,2,2,2,2,78,106",
"index_merge": {
"union": {
"range": {
"key": "IX_tcontent_display",
"used_key_parts": ["Display"]
},
"range": {
"key": "IX_tcontent_display",
"used_key_parts": ["Display"]
},
"intersect": {
"range": {
"key": "IX_tcontent_approved",
"used_key_parts": ["Approved"]
},
"range": {
"key": "IX_tcontent_active",
"used_key_parts": ["Active"]
},
"range": {
"key": "IX_tcontent_display",
"used_key_parts": ["Display"]
},
"range": {
"key": "IX_TContent_2",
"used_key_parts": ["SiteID"]
},
"range": {
"key": "IX_TContent_5",
"used_key_parts": ["ModuleID"]
}
}
}
},
"r_loops": 1,
"rows": 2583,
"r_rows": 3966,
"r_total_time_ms": 15.183,
"filtered": 96.129,
"r_filtered": 98.664,
"attached_condition": "tcontent.Active = 1 and tcontent.Approved = 1 and tcontent.searchExclude = 0 and tcontent.SiteID = 'CAE' and tcontent.ModuleID = '00000000000000000000000000000000000' and tcontent.ContentID <> '00000000000000000000000000000000001' and tcontent.`Type` <> 'Module' and (tcontent.Display = 1 or tcontent.Display = 2 and (tcontent.DisplayStart <= '2018-01-09 15:17:00' and (tcontent.DisplayStop >= '2018-01-09 15:17:00' or tcontent.DisplayStop is null) or tcontent.DisplayStart <= '2019-01-09 15:17:00' and (tcontent.DisplayStop >= '2018-01-09 15:17:00' or tcontent.DisplayStop is null))) and (tcontent.mobileExclude is null or tcontent.mobileExclude in (0,1))"
},
"table": {
"table_name": "<subquery2>",
"access_type": "eq_ref",
"possible_keys": ["distinct_key"],
"key": "distinct_key",
"key_length": "105",
"used_key_parts": ["contentHistID"],
"ref": ["func"],
"r_loops": 3913,
"rows": 1,
"r_rows": 5.1e-4,
"r_total_time_ms": 6.2577,
"filtered": 100,
"r_filtered": 100,
"attached_condition": "tcontent.Display = 1 or tcontent.Display = 2 and (tcontent.DisplayStart <= '2018-01-09 15:17:00' and (tcontent.DisplayStop >= '2018-01-09 15:17:00' or tcontent.DisplayStop is null) or tcontent.DisplayStart <= '2019-01-09 15:17:00' and (tcontent.DisplayStop >= '2018-01-09 15:17:00' or tcontent.DisplayStop is null))",
"materialized": {
"unique": 1,
"query_block": {
"select_id": 2,
"table": {
"table_name": "tcontentcategories",
"access_type": "ALL",
"possible_keys": ["PRIMARY"],
"r_loops": 1,
"rows": 166,
"r_rows": 166,
"r_total_time_ms": 0.2246,
"filtered": 100,
"r_filtered": 0.6024,
"attached_condition": "tcontentcategories.path like '%D3386B7B-5056-8740-7CA949A8C39FACF3%'"
},
"table": {
"table_name": "tcontentcategoryassign",
"access_type": "ref",
"possible_keys": [
"PRIMARY",
"IX_tcontentcategoryassign_categoryID"
],
"key": "IX_tcontentcategoryassign_categoryID",
"key_length": "105",
"used_key_parts": ["categoryID"],
"ref": ["dbMuraCMS.tcontentcategories.categoryID"],
"r_loops": 1,
"rows": 53,
"r_rows": 33,
"r_total_time_ms": 0.0413,
"filtered": 100,
"r_filtered": 100,
"using_index": true
}
}
}
},
"table": {
"table_name": "tfiles",
"access_type": "eq_ref",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "105",
"used_key_parts": ["fileID"],
"ref": ["dbMuraCMS.tcontent.FileID"],
"r_loops": 2,
"rows": 1,
"r_rows": 1,
"r_total_time_ms": 0.0109,
"filtered": 100,
"r_filtered": 100,
"attached_condition": "trigcond(trigcond(tcontent.FileID is not null))"
},
"table": {
"table_name": "tcontentstats",
"access_type": "eq_ref",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "182",
"used_key_parts": ["contentID", "siteID"],
"ref": ["dbMuraCMS.tcontent.ContentID", "dbMuraCMS.tcontent.SiteID"],
"r_loops": 2,
"rows": 1,
"r_rows": 0,
"r_total_time_ms": 0.0127,
"filtered": 100,
"r_filtered": 100,
"attached_condition": "trigcond(trigcond(tcontent.ContentID is not null and tcontent.SiteID is not null))"
},
"table": {
"table_name": "tparent",
"access_type": "ref",
"possible_keys": [
"IX_TContent",
"IX_TContent_2",
"IX_tcontent_active",
"ntID_Type_subType_Display_DisplayStart_DisplayStop_mobileExclude",
"ix_tcontent_SiteID_Active_Filename_Type"
],
"key": "IX_TContent",
"key_length": "106",
"used_key_parts": ["ContentID"],
"ref": ["dbMuraCMS.tcontent.ParentID"],
"r_loops": 2,
"rows": 1,
"r_rows": 238,
"r_total_time_ms": 1.5375,
"filtered": 100,
"r_filtered": 0.4202,
"attached_condition": "trigcond(tcontent.Display = 1 or tcontent.Display = 2 and (tparent.`Type` <> 'Calendar' and tcontent.DisplayStart <= '2018-01-09 15:17:00' and (tcontent.DisplayStop >= '2018-01-09 15:17:00' or tcontent.DisplayStop is null) or tparent.`Type` = 'Calendar' and tcontent.DisplayStart <= '2019-01-09 15:17:00' and (tcontent.DisplayStop >= '2018-01-09 15:17:00' or tcontent.DisplayStop is null))) and trigcond(tparent.SiteID = tcontent.SiteID and tparent.Active = 1 and trigcond(tcontent.ParentID is not null))"
},
"table": {
"table_name": "tcontentfilemetadata",
"access_type": "ALL",
"possible_keys": [
"IX_tcontentfilemetadata_contenthistid",
"IX_tcontentfilemetadata_fileid"
],
"r_loops": 2,
"rows": 1,
"r_rows": 0,
"r_total_time_ms": 0.0045,
"filtered": 100,
"r_filtered": 100,
"attached_condition": "trigcond(tcontentfilemetadata.fileid = tcontent.FileID and tcontentfilemetadata.contenthistid = tcontent.ContentHistID)"
}
}
}
}
}