feat(ENodeConfigure):创建新超表的时候自动适配是否为分布式

This commit is contained in:
Yu Sun
2022-10-07 19:26:51 +08:00
parent fbe6bda621
commit 8b5b345202

View File

@@ -62,7 +62,13 @@ class ENodeConfigure {
", $table_name ", $table_name
)); ));
if (!in_array($table_name, pg_fetch_all_columns($table_exists, 1))) { if (!in_array($table_name, pg_fetch_all_columns($table_exists, 1))) {
$res[] = pg_query($this -> dbconn, sprintf("SELECT create_hypertable('\"%s\"', 'capture_time')", $table_name)); $res[] = $node_count = pg_query($this -> dbconn, "SELECT COUNT(*) from timescaledb_information.data_nodes");
if (intval(pg_fetch_assoc($node_count)['count']) === 0) {
$res[] = pg_query($this -> dbconn, sprintf("SELECT create_hypertable('\"%s\"', 'capture_time')", $table_name));
} else {
$res[] = pg_query($this -> dbconn, sprintf("SELECT create_distributed_hypertable('\"%s\"', 'capture_time', 'code', 'device_code', 'parent_device_code', 'batch')", $table_name));
}
$res[] = pg_query($this -> dbconn, sprintf( $res[] = pg_query($this -> dbconn, sprintf(
'CREATE INDEX ON "%s" (v_string, v_int, v_float, v_bool, capture_time DESC) 'CREATE INDEX ON "%s" (v_string, v_int, v_float, v_bool, capture_time DESC)
WHERE COALESCE(v_string, v_int::text, v_float::text, v_bool::text) IS NOT NULL WHERE COALESCE(v_string, v_int::text, v_float::text, v_bool::text) IS NOT NULL