+++ /dev/null
-;;; Directory Local Variables
-;;; For more information see (info "(emacs) Directory Variables")
-
-((fundamental-mode
- (mode . snippet))
- )
-
+++ /dev/null
-# -*- mode: snippet -*-
-# name: busy-hours
-# key: bh_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# https://www.vertica.com/blog/find-the-busiest-hour-in-the-day-for-i-o/
-# --
-
-SELECT *
- FROM (SELECT "HOUR", "Total IO (GB)", "Read IO (GB)", "Write IO (GB)"
- FROM (SELECT MIN(TRUNC(start_time)) start_time,
- DATE_TRUNC('hour', start_time) as "HOUR",
- (SUM(read_kbytes_per_sec) + SUM(written_kbytes_per_sec)) * 60/1024/1024 as "Total IO (GB)",
- SUM(read_kbytes_per_sec) * 60/1024/1024 as "Read IO (GB)",
- SUM(written_kbytes_per_sec) * 60/1024/1024 as "Write IO (GB)"
- FROM v_monitor.io_usage
- GROUP BY 2) foo
- WHERE start_time >= TRUNC(SYSDATE) - 5 -- LAST 5 DAYS!
- LIMIT 1 OVER (PARTITION BY start_time ORDER BY start_time, "Total IO (GB)" DESC)) foo2
- ORDER BY "HOUR" DESC;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: check_rle_overridden
-# key: rle_check_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-select
- qe.user_name,
- count(*)
-from
- v_monitor.query_events qe
- join v_monitor.query_requests qr
- on qr.transaction_id = qe.transaction_id
- and qr.statement_id = qe.statement_id
-where
- qr.request_type = 'QUERY'
- and qe.event_type = 'RLE_OVERRIDDEN'
- and to_char(event_timestamp, 'YYYY-MM-DD') = '${1:`(format-time-string "%Y-%m-%d")`}'
-group by
- 1
-;
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: config-changes
-# key: config-changes
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# https://www.vertica.com/blog/generate-ddl-for-changed-configuration-parameters/
-# --
- SELECT DISTINCT ddl
- FROM (SELECT CASE
- WHEN current_level = 'DATABASE' OR (current_level = 'DEFAULT' AND INSTR(allowed_levels, 'DATABASE') > 0) THEN
- 'SELECT set_config_parameter(''' || parameter || ''', ''' || value || ''');'
- WHEN current_level = 'NODE' THEN
- 'ALTER NODE ' || configuration_changes.node_name || ' SET ' || parameter || ' = ''' || value || ''';'
- END AS ddl
- FROM configuration_changes
- JOIN configuration_parameters
- ON parameter = parameter_name
- WHERE allowed_levels <> 'SESSION'
- LIMIT 1 OVER (PARTITION BY configuration_changes.node_name, parameter ORDER BY event_timestamp DESC)) foo
- ORDER BY 1;$0
+++ /dev/null
-# -*- mode: snippet -*-
-# name: current_epoch
-# key: epo_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT current_epoch, ahm_epoch, last_good_epoch FROM v_monitor.system;
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: errors
-# key: errors_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT DISTINCT error_level, message FROM error_messages $0WHERE message ILIKE 'Vertica suggests%';
+++ /dev/null
-# -*- mode: snippet -*-
-# name: external_table_details
-# key: etd_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT table_name, source_format, total_file_size_bytes FROM external_table_details;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: format_numbers
-# key: _fn_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# --
-TO_CHAR( $0, '999g999g999g999') AS
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: get-partitions
-# key: get-part
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM v_monitor.partitions WHERE table_schema = '$1' AND projection_name LIKE '%$2%';$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: get-projections
-# key: get-proj
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT GET_PROJECTIONS('$1');$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: grants
-# key: grants_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT grantee, object_name, privileges_description FROM v_catalog.grants WHERE object_type = '${1:$$(yas-choose-value '("RESOURCEPOOL" "ROLE" "SCHEMA" "TABLE" "VIEW" "STORAGELOCATION"))}' ORDER BY grantee $0LIMIT 50;
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: last-statement-timing
-# key: lst_
-# group: vertica
-# --
-SELECT last_statement,
- last_statement_duration_us / 1000000.0 last_statement_duration_seconds
-FROM current_session;
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: last-vertica-updates
-# key: lvu_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# --
-SELECT time,
- new_version
- FROM dc_upgrades
- LIMIT 1 OVER (PARTITION BY new_version
- ORDER BY TIME DESC);
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: licence-history
-# key: lic_history
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# https://www.vertica.com/blog/track-license-usage-over-time/
-# --
- SELECT * FROM (
- SELECT TRUNC(audit_start_timestamp)::DATE the_date, usage_percent * 100 AS usage_percent
- FROM license_audits
- WHERE audited_data = 'Total'
- LIMIT 1 OVER (PARTITION BY TRUNC(audit_start_timestamp) ORDER BY audit_start_timestamp DESC)
- ) foo
- ORDER BY 1 DESC
- LIMIT 7;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: list-backups
-# key: ls_backups
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM v_monitor.database_backups ORDER BY 1 DESC;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: list-tables-row-count-size
-# key: ls-tables
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT tbl.table_schema AS "Schema Name",
- tbl.table_name AS "Table Name",
- to_char(sum(prs.ros_row_count)/count(DISTINCT prs.projection_name), '999G999G999G999') AS "No Of Rows",
- to_char(sum(prs.ros_used_bytes)/count(DISTINCT prs.projection_name), '999G999G999G999G999') AS "Size In Bytes"
-FROM TABLES tbl
-JOIN projections prj ON tbl.table_id = prj.anchor_table_id
-JOIN projection_storage prs ON prj.projection_name = prs.projection_name
-GROUP BY 1, 2
-ORDER BY 1, 2;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: show nodes
-# key: nodes_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM nodes;
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: pool_queues
-# key: pq_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# https://www.vertica.com/blog/calculate-request-queue-length-quick-tip/?utm_campaign=00164962
-# https://www.vertica.com/docs/latest/HTML/index.htm#Authoring/SQLReferenceManual/SystemTables/MONITOR/RESOURCE_ACQUISITIONS.htm
-# --
-SELECT node_name, request_type, transaction_id, statement_id, pool_name, (acquisition_timestamp - queue_entry_timestamp) request_queue_length FROM v_monitor.resource_acquisitions WHERE pool_name = '${1:general}' ${2:AND (acquisition_timestamp - queue_entry_timestamp) > '1 second'} ORDER BY (acquisition_timestamp - queue_entry_timestamp) DESC ${3:LIMIT 42};$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: projection_storage
-# key: ps_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT node_name,
- projection_schema,
- projection_name,
- (SUM(used_bytes)/1024^3)::INT size_in_GB
- FROM projection_storage
- WHERE anchor_table_name = '$1'
- GROUP BY 1,2,3
- ORDER BY 2,3,1
- LIMIT 20;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: pset_footer
-# key: footer_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-\pset footer 0$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: query-acquisition-queue
-# key: query-acq-queue
-# group: vertica
-# documentation: https://www.vertica.com/blog/calculate-request-queue-length-quick-tip/?utm_campaign=00164962
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT node_name,
- request_type,
- transaction_id,
- statement_id,
- pool_name,
- (acquisition_timestamp - queue_entry_timestamp) request_queue_length
-FROM v_monitor.resource_acquisitions
-WHERE pool_name = 'general'
-ORDER BY (acquisition_timestamp - queue_entry_timestamp) DESC
-LIMIT 1;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: query-event-issues
-# key: qei_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# https://www.vertica.com/blog/find-and-fix-issues-from-vertica-query-events/
-# --
-SELECT event_description,
- suggested_action,
- COUNT(*)
- FROM query_events
- WHERE suggested_action IS NOT NULL
- AND suggested_action <> 'Informational; No user action is necessary'
- GROUP BY 1,
- 2
- ORDER BY 3 DESC;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: query-long-acquisitions
-# key: query-long-acq
-# group: vertica
-# documentation: https://www.vertica.com/blog/calculate-request-queue-length-quick-tip/?utm_campaign=00164962
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT node_name,
- request_type,
- transaction_id,
- statement_id,
- pool_name,
- (acquisition_timestamp - queue_entry_timestamp) request_queue_length
-FROM v_monitor.resource_acquisitions
-WHERE pool_name = 'general'
-AND (acquisition_timestamp - queue_entry_timestamp) > '1 second'
-ORDER BY (acquisition_timestamp - queue_entry_timestamp) DESC;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: query-requests
-# key: qr_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# --
-SELECT request
- FROM v_monitor.query_requests
- WHERE user_name = '$1'
- AND request_type = '${2:$$(yas-choose-value '("QUERY" "SHOW" "SET" "DDL" "TRUNCATE" "TRANSACTION" "LOAD"))}'
- AND start_timestamp::DATE = '${3:`(insert (format-time-string "%Y-%m-%d"))`}'
- AND request_label LIKE '$4'
- ORDER BY start_timestamp ASC;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: query-requests-expensive
-# key: qre_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-#
-# expensive queries, based on threads, memory, duration.
-# Also includes the last transaction_id to find the query.
-# and the range of the times it's ran from and to.
-# targets just JOIN and GROUP BY SPILL events
-#
-# --
-SELECT REGEXP_REPLACE(REGEXP_REPLACE(substr(qr.request, 1, 500), '\d'), '\''[\S\s]?\''', '''?''' ) AS query,
- MAX(qr.transaction_id) AS last_trans_id,
- AVG(qr.request_duration_ms)/1000/60 AS avg_duration_mins,
- AVG(ra.thread_count) AS avg_threads,
- TO_CHAR(AVG(memory_inuse_kb)/1024, '999,999') AS avg_mem_mb,
- (SUM(qr.request_duration_ms) * COUNT(1))/1000 AS total_duration_secs,
- MAX(eee.event_type) AS event_type,
- TRUNC(MIN(qr.start_timestamp), 'MI') AS first_run,
- TRUNC(MAX(qr.start_timestamp), 'MI') AS last_run,
- (SUM(qr.request_duration_ms) * COUNT(1)) * SUM(ra.thread_count) AS total_cost,
- COUNT(1) AS num_runs
- FROM v_monitor.query_requests qr
- JOIN (SELECT transaction_id, statement_id, event_type
- FROM v_internal.dc_execution_engine_events
- WHERE node_name = (SELECT MIN(node_name)
- FROM v_catalog.nodes)
- ) eee USING (transaction_id, statement_id)
- LEFT JOIN (SELECT transaction_id, statement_id, thread_count, memory_inuse_kb, duration_ms
- FROM v_monitor.resource_acquisitions
- WHERE node_name = (SELECT MIN(node_name)
- FROM v_catalog.nodes)
- ) ra USING (transaction_id, statement_id)
- WHERE start_timestamp::date > CURRENT_DATE() -1
- AND NOT qr.is_executing
- AND eee.event_type IN ('GROUP_BY_SPILLED', 'JOIN_SPILLED')
- GROUP BY 1
-HAVING COUNT(*) > 3
- ORDER BY total_cost DESC
- LIMIT 40;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: query-requests-overview
-# key: qro_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
-# --
-SELECT user_name,
- start_timestamp,
- request_duration_ms,
- transaction_id,
- STATEMENT_ID,
- substr(request, 0, 1000) AS request
- FROM v_monitor.query_requests
-WHERE transaction_id > 0
-ORDER BY request_duration_ms DESC
-LIMIT 10;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: query-times
-# key: qt_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT DISTINCT theday,
- user_name,
- (min_dat / 1000) AS min_sec,
- (max_dat / 1000) AS max_sec,
- (avg_dat / 1000) AS avg_sec,
- (median_dat / 1000) AS median_sec,
- query_cnt
-FROM
- (SELECT date(end_timestamp::TIMESTAMP) AS theday,
- user_name,
- min(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) min_dat,
- max(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) max_dat,
- avg(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) avg_dat,
- median(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) median_dat,
- count(*) over(partition BY date(end_timestamp::TIMESTAMP), user_name) AS query_cnt
- FROM query_requests
- WHERE is_executing IS FALSE
- AND request ILIKE '%table%'
- AND NOT (request LIKE 'SELECT * FROM columns%'
- OR request LIKE '%query_requests%') ) my_alias
-ORDER BY 1 DESC, 2;
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: rebalance_projection_status
-# key: rps_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT projection_name, rebalance_method, separated_percent, transferred_percent
- FROM v_monitor.rebalance_projection_status
- WHERE rebalance_method = 'ELASTIC_CLUSTER'
- AND (
- separated_percent <> 0
- AND separated_percent <> 100
- )
- OR (
- transferred_percent <> 0
- AND transferred_percent <> 100
- )
- AND is_latest
- ORDER BY 1;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: rebalance_status
-# key: rs_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT rebalance_method rebalance_method,
- status,
- count(*) AS COUNT
-FROM
- (SELECT rebalance_method,
- CASE
- WHEN (separated_percent = 100
- AND transferred_percent = 100) THEN 'Completed'
- WHEN (separated_percent <> 0
- AND separated_percent <> 100)
- OR (transferred_percent <> 0
- AND transferred_percent <> 100) THEN 'In Progress'
- ELSE 'Queued'
- END AS status
- FROM v_monitor.rebalance_projection_status
- WHERE is_latest) AS tab
-GROUP BY 1,
- 2
-ORDER BY 1,
- 2;$0
+++ /dev/null
-# -*- mode: snippet -*-
-# name: rebalance_times
-# key: rt_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT dc_rebalanced_projections.node_name,
- projection_schema,
- projection_name,
- start_time,
- time -start_time duration
- FROM v_internal.dc_rebalanced_projections
- ORDER BY 5 DESC
- LIMIT 100;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: resource-pool-move
-# key: rpmv
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM resource_pool_move ORDER BY move_timestamp DESC LIMIT 40;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: resource_pool_status
-# key: rps_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT node_name,
- pool_name,
- TO_CHAR( memory_size_kb / 1024, '999g999g999g999') AS memory_size_mb,
- TO_CHAR( max_memory_size_kb / 1024, '999g999g999g999') AS max_memory_size_mb,
- TO_CHAR( memory_size_actual_kb / 1024, '999g999g999g999') AS memory_size_actual_mb,
- planned_concurrency,
- TO_CHAR( query_budget_kb / 1024 , '999g999g999g999') AS query_budget_mb
- FROM resource_pool_status
- WHERE pool_name = '$1'
- ORDER BY 1,2;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: resource_pool_status2
-# key: rps2_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT sysdate AS CURRENT_TIME,
- node_name,
- pool_name,
- TO_CHAR( memory_inuse_kb / 1024, '999g999g999g999') AS memory_inuse_mb,
- TO_CHAR( general_memory_borrowed_kb / 1024, '999g999g999g999') AS general_memory_borrowed_mb,
- running_query_count
- FROM resource_pool_status
-ORDER BY 1,3,2;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: resource_pools
-# key: pools_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM resource_pools;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: resources
-# key: res_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM ${1:$$(yas-choose-value '("resource_pool_status" "resource_pool_move" "resource_rejections" "resource_rejection_details ORDER BY 1"))};$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: ros_count
-# key: ro_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT node_name,
- projection_schema,
- projection_name,
- SUM(ros_count) AS ros_count
- FROM v_monitor.projection_storage
- GROUP BY node_name,
- projection_schema,
- projection_name
- HAVING SUM(ros_count) > 100
- ORDER BY ros_count DESC;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: segmentation-islands1
-# key: si1_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-#
-# https://www.vertica.com/blog/beware-segmentation-islands/
-#
-# --
-SELECT REGEXP_REPLACE(SUBSTR(segment_expression, 1, 500), '\w+\.'),
- COUNT(*)
- FROM projections
- WHERE projection_name NOT ILIKE '%b1'
- GROUP BY 1
- ORDER BY 2 DESC;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: segmentation-islands2
-# key: si2_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-#
-# https://www.vertica.com/blog/beware-segmentation-islands/
-#
-# --
-SELECT projection_schema || '.' || p.projection_name, REGEXP_REPLACE(SUBSTR(p.segment_expression, 1, 500), '\w+\.'),
- pc.projection_column_name
- FROM projections p
- JOIN projection_columns pc USING (projection_id)
- WHERE REGEXP_REPLACE(SUBSTR(p.segment_expression, 1, 500), '\w+\.')
- IN (SELECT REGEXP_REPLACE(SUBSTR (p.segment_expression, 1, 500), '\w+\.')
- FROM projections p
- WHERE p.projection_name NOT ILIKE '%b1'
- AND is_segmented
- GROUP BY 1
- HAVING COUNT(*) = 1 )
- AND p.projection_name NOT ILIKE '%b1'
- AND pc.projection_column_name IN (
- SELECT hash_expr FROM (SELECT replace(substr(regexp_replace(substr(p.segment_expression, 1, 500), '\w+\.'), 6), ')', '') AS hash_expr, COUNT(*)
- FROM projections p
- WHERE p.projection_name NOT ILIKE '%b1'
- AND is_segmented
- GROUP BY 1
- ORDER BY 2 DESC
- LIMIT 20 ) AS foo )
- ORDER BY 1, 2, 3;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: sessions
-# key: sess_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM sessions;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: storage-containers
-# key: storage-containers
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT s.node_name,
- p.table_schema,
- s.projection_name,
- count(DISTINCT s.storage_oid) storage_container_count,
- count(DISTINCT partition_key) partition_count,
- count(r.rosid) ros_file_count
-FROM storage_containers s
-LEFT OUTER JOIN partitions p ON s.storage_oid = p.ros_id
-JOIN vs_ros r ON r.delid = s.storage_oid
-GROUP BY 1,
- 2,
- 3
-ORDER BY 4 DESC LIMIT 50;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: storage-locations
-# key: storage-locations
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT * FROM v_catalog.grants gra, storage_locations loc WHERE gra.object_id = loc.location_id;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: table_locks
-# key: tl_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT locks.lock_mode,
- locks.lock_scope,
- substr(locks.transaction_description, 1, 100) AS "left",
- locks.request_timestamp,
- locks.grant_timestamp
- FROM v_monitor.locks;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: user_sessions
-# key: ussess_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT session_id, transaction_start FROM sessions WHERE user_name = '$1' ORDER BY 2 desc;$0
\ No newline at end of file
+++ /dev/null
-# -*- mode: snippet -*-
-# name: vertica_users
-# key: vertu_
-# group: vertica
-# condition: (if (string-equal sql-product 'vertica)t)
-# --
-SELECT user_name,resource_pool,default_roles FROM v_catalog.users ORDER BY 1;
\ No newline at end of file
+++ /dev/null
-sql-interactive-mode
+++ /dev/null
-;;; vertica-snippets-autoloads.el --- automatically extracted autoloads
-;;
-;;; Code:
-
-(add-to-list 'load-path (directory-file-name
- (or (file-name-directory #$) (car load-path))))
-
-\f
-;;;### (autoloads nil "vertica-snippets" "vertica-snippets.el" (0
-;;;;;; 0 0 0))
-;;; Generated autoloads from vertica-snippets.el
-
-(autoload 'vertica-snippets-initialize "vertica-snippets" "\
-Add snippet dir to yas-snippet-dirs and load it.
-
-\(fn)" nil nil)
-
-(eval-after-load 'yasnippet '(vertica-snippets-initialize))
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "vertica-snippets" '("vertica-snippets-dir")))
-
-;;;***
-\f
-;;;### (autoloads nil nil ("vertica-snippets-pkg.el") (0 0 0 0))
-
-;;;***
-\f
-;; Local Variables:
-;; version-control: never
-;; no-byte-compile: t
-;; no-update-autoloads: t
-;; coding: utf-8
-;; End:
-;;; vertica-snippets-autoloads.el ends here
+++ /dev/null
-(define-package "vertica-snippets" "20191213.1109" "Yasnippets for Vertica"
- '((yasnippet "0.6.1"))
- :keywords
- '("convenience" "snippets")
- :authors
- '(("Andreas Gerler" . "baronNOSPAMbundesbrandschatzamt.de"))
- :maintainer
- '("Andreas Gerler" . "baronNOSPAMbundesbrandschatzamt.de")
- :url "https://github.com/baron42bba/vertica-snippets")
-;; Local Variables:
-;; no-byte-compile: t
-;; End:
+++ /dev/null
-;;; vertica-snippets.el --- Yasnippets for Vertica
-
-;; Copyright (C) 2018 Andreas Gerler
-;; keywords: convenience,snippets
-;; Version: 0.1.0
-;; Package-Requires: ((yasnippet "0.6.1"))
-
-;; Author: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
-;; Maintainer: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
-
-;; URL: https://github.com/baron42bba/vertica-snippets
-
-;; Permission is hereby granted, free of charge, to any person obtaining
-;; a copy of this software and associated documentation files (the
-;; "Software"), to deal in the Software without restriction, including
-;; without limitation the rights to use, copy, modify, merge, publish,
-;; distribute, sublicense, and/or sell copies of the Software, and to
-;; permit persons to whom the Software is furnished to do so, subject to
-;; the following conditions:
-
-;; The above copyright notice and this permission notice shall be
-;; included in all copies or substantial portions of the Software.
-
-;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-;;; Commentary:
-
-;; A collection of yasnippet snippets to be used with the Vertica Analytics Platform
-
-;;; Code:
-
-(require 'yasnippet)
-
-(defvar vertica-snippets-dir (file-name-directory (or (buffer-file-name)
- load-file-name)))
-
-;;;###autoload
-(defun vertica-snippets-initialize ()
- "Add snippet dir to yas-snippet-dirs and load it."
- (let ((snip-dir (expand-file-name "snippets" vertica-snippets-dir)))
- (add-to-list 'yas-snippet-dirs snip-dir t)
- (yas-load-directory snip-dir)))
-
-;;;###autoload
-(eval-after-load 'yasnippet
- '(vertica-snippets-initialize))
-
-(provide 'vertica-snippets)
-;;; vertica-snippets.el ends here
--- /dev/null
+;;; Directory Local Variables
+;;; For more information see (info "(emacs) Directory Variables")
+
+((fundamental-mode
+ (mode . snippet))
+ )
+
--- /dev/null
+# -*- mode: snippet -*-
+# name: busy-hours
+# key: bh_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# https://www.vertica.com/blog/find-the-busiest-hour-in-the-day-for-i-o/
+# --
+
+SELECT *
+ FROM (SELECT "HOUR", "Total IO (GB)", "Read IO (GB)", "Write IO (GB)"
+ FROM (SELECT MIN(TRUNC(start_time)) start_time,
+ DATE_TRUNC('hour', start_time) as "HOUR",
+ (SUM(read_kbytes_per_sec) + SUM(written_kbytes_per_sec)) * 60/1024/1024 as "Total IO (GB)",
+ SUM(read_kbytes_per_sec) * 60/1024/1024 as "Read IO (GB)",
+ SUM(written_kbytes_per_sec) * 60/1024/1024 as "Write IO (GB)"
+ FROM v_monitor.io_usage
+ GROUP BY 2) foo
+ WHERE start_time >= TRUNC(SYSDATE) - 5 -- LAST 5 DAYS!
+ LIMIT 1 OVER (PARTITION BY start_time ORDER BY start_time, "Total IO (GB)" DESC)) foo2
+ ORDER BY "HOUR" DESC;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: check_rle_overridden
+# key: rle_check_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+select
+ qe.user_name,
+ count(*)
+from
+ v_monitor.query_events qe
+ join v_monitor.query_requests qr
+ on qr.transaction_id = qe.transaction_id
+ and qr.statement_id = qe.statement_id
+where
+ qr.request_type = 'QUERY'
+ and qe.event_type = 'RLE_OVERRIDDEN'
+ and to_char(event_timestamp, 'YYYY-MM-DD') = '${1:`(format-time-string "%Y-%m-%d")`}'
+group by
+ 1
+;
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: config-changes
+# key: config-changes
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# https://www.vertica.com/blog/generate-ddl-for-changed-configuration-parameters/
+# --
+ SELECT DISTINCT ddl
+ FROM (SELECT CASE
+ WHEN current_level = 'DATABASE' OR (current_level = 'DEFAULT' AND INSTR(allowed_levels, 'DATABASE') > 0) THEN
+ 'SELECT set_config_parameter(''' || parameter || ''', ''' || value || ''');'
+ WHEN current_level = 'NODE' THEN
+ 'ALTER NODE ' || configuration_changes.node_name || ' SET ' || parameter || ' = ''' || value || ''';'
+ END AS ddl
+ FROM configuration_changes
+ JOIN configuration_parameters
+ ON parameter = parameter_name
+ WHERE allowed_levels <> 'SESSION'
+ LIMIT 1 OVER (PARTITION BY configuration_changes.node_name, parameter ORDER BY event_timestamp DESC)) foo
+ ORDER BY 1;$0
--- /dev/null
+# -*- mode: snippet -*-
+# name: current_epoch
+# key: epo_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT current_epoch, ahm_epoch, last_good_epoch FROM v_monitor.system;
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: errors
+# key: errors_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT DISTINCT error_level, message FROM error_messages $0WHERE message ILIKE 'Vertica suggests%';
--- /dev/null
+# -*- mode: snippet -*-
+# name: external_table_details
+# key: etd_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT table_name, source_format, total_file_size_bytes FROM external_table_details;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: format_numbers
+# key: _fn_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# --
+TO_CHAR( $1, '999g999g999g990d99') AS $0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: get-partitions
+# key: get-part
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM v_monitor.partitions WHERE table_schema = '$1' AND projection_name LIKE '%$2%';$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: get-projections
+# key: get-proj
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT GET_PROJECTIONS('$1');$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: grants
+# key: grants_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT grantee, object_name, privileges_description FROM v_catalog.grants WHERE object_type = '${1:$$(yas-choose-value '("RESOURCEPOOL" "ROLE" "SCHEMA" "TABLE" "VIEW" "STORAGELOCATION"))}' ORDER BY grantee $0LIMIT 50;
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: last-statement-timing
+# key: lst_
+# group: vertica
+# --
+SELECT last_statement,
+ last_statement_duration_us / 1000000.0 last_statement_duration_seconds
+FROM current_session;
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: last-vertica-updates
+# key: lvu_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# --
+SELECT time,
+ new_version
+ FROM dc_upgrades
+ LIMIT 1 OVER (PARTITION BY new_version
+ ORDER BY TIME DESC);
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: licence-history
+# key: lic_history
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# https://www.vertica.com/blog/track-license-usage-over-time/
+# --
+ SELECT * FROM (
+ SELECT TRUNC(audit_start_timestamp)::DATE the_date, usage_percent * 100 AS usage_percent
+ FROM license_audits
+ WHERE audited_data = 'Total'
+ LIMIT 1 OVER (PARTITION BY TRUNC(audit_start_timestamp) ORDER BY audit_start_timestamp DESC)
+ ) foo
+ ORDER BY 1 DESC
+ LIMIT 7;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: list-backups
+# key: ls_backups
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM v_monitor.database_backups ORDER BY 1 DESC;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: list-tables-row-count-size
+# key: ls-tables
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT tbl.table_schema AS "Schema Name",
+ tbl.table_name AS "Table Name",
+ to_char(sum(prs.ros_row_count)/count(DISTINCT prs.projection_name), '999G999G999G999') AS "No Of Rows",
+ to_char(sum(prs.ros_used_bytes)/count(DISTINCT prs.projection_name), '999G999G999G999G999') AS "Size In Bytes"
+FROM TABLES tbl
+JOIN projections prj ON tbl.table_id = prj.anchor_table_id
+JOIN projection_storage prs ON prj.projection_name = prs.projection_name
+GROUP BY 1, 2
+ORDER BY 1, 2;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: show nodes
+# key: nodes_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM nodes;
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: pool_queues
+# key: pq_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# https://www.vertica.com/blog/calculate-request-queue-length-quick-tip/?utm_campaign=00164962
+# https://www.vertica.com/docs/latest/HTML/index.htm#Authoring/SQLReferenceManual/SystemTables/MONITOR/RESOURCE_ACQUISITIONS.htm
+# --
+SELECT node_name, request_type, transaction_id, statement_id, pool_name, (acquisition_timestamp - queue_entry_timestamp) request_queue_length FROM v_monitor.resource_acquisitions WHERE pool_name = '${1:general}' ${2:AND (acquisition_timestamp - queue_entry_timestamp) > '1 second'} ORDER BY (acquisition_timestamp - queue_entry_timestamp) DESC ${3:LIMIT 42};$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: projection_storage
+# key: ps_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT node_name,
+ projection_schema,
+ projection_name,
+ (SUM(used_bytes)/1024^3)::INT size_in_GB
+ FROM projection_storage
+ WHERE anchor_table_name = '$1'
+ GROUP BY 1,2,3
+ ORDER BY 2,3,1
+ LIMIT 20;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: pset_footer
+# key: footer_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+\pset footer 0$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: query-acquisition-queue
+# key: query-acq-queue
+# group: vertica
+# documentation: https://www.vertica.com/blog/calculate-request-queue-length-quick-tip/?utm_campaign=00164962
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT node_name,
+ request_type,
+ transaction_id,
+ statement_id,
+ pool_name,
+ (acquisition_timestamp - queue_entry_timestamp) request_queue_length
+FROM v_monitor.resource_acquisitions
+WHERE pool_name = 'general'
+ORDER BY (acquisition_timestamp - queue_entry_timestamp) DESC
+LIMIT 1;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: query-event-issues
+# key: qei_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# https://www.vertica.com/blog/find-and-fix-issues-from-vertica-query-events/
+# --
+SELECT event_description,
+ suggested_action,
+ COUNT(*)
+ FROM query_events
+ WHERE suggested_action IS NOT NULL
+ AND suggested_action <> 'Informational; No user action is necessary'
+ GROUP BY 1,
+ 2
+ ORDER BY 3 DESC;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: query-long-acquisitions
+# key: query-long-acq
+# group: vertica
+# documentation: https://www.vertica.com/blog/calculate-request-queue-length-quick-tip/?utm_campaign=00164962
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT node_name,
+ request_type,
+ transaction_id,
+ statement_id,
+ pool_name,
+ (acquisition_timestamp - queue_entry_timestamp) request_queue_length
+FROM v_monitor.resource_acquisitions
+WHERE pool_name = 'general'
+AND (acquisition_timestamp - queue_entry_timestamp) > '1 second'
+ORDER BY (acquisition_timestamp - queue_entry_timestamp) DESC;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: query-requests
+# key: qr_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# --
+SELECT request
+ FROM v_monitor.query_requests
+ WHERE user_name = '$1'
+ AND request_type = '${2:$$(yas-choose-value '("QUERY" "SHOW" "SET" "DDL" "TRUNCATE" "TRANSACTION" "LOAD"))}'
+ AND start_timestamp::DATE = '${3:`(insert (format-time-string "%Y-%m-%d"))`}'
+ AND request_label LIKE '$4'
+ ORDER BY start_timestamp ASC;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: query-requests-expensive
+# key: qre_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+#
+# expensive queries, based on threads, memory, duration.
+# Also includes the last transaction_id to find the query.
+# and the range of the times it's ran from and to.
+# targets just JOIN and GROUP BY SPILL events
+#
+# --
+SELECT REGEXP_REPLACE(REGEXP_REPLACE(substr(qr.request, 1, 500), '\d'), '\''[\S\s]?\''', '''?''' ) AS query,
+ MAX(qr.transaction_id) AS last_trans_id,
+ AVG(qr.request_duration_ms)/1000/60 AS avg_duration_mins,
+ AVG(ra.thread_count) AS avg_threads,
+ TO_CHAR(AVG(memory_inuse_kb)/1024, '999,999') AS avg_mem_mb,
+ (SUM(qr.request_duration_ms) * COUNT(1))/1000 AS total_duration_secs,
+ MAX(eee.event_type) AS event_type,
+ TRUNC(MIN(qr.start_timestamp), 'MI') AS first_run,
+ TRUNC(MAX(qr.start_timestamp), 'MI') AS last_run,
+ (SUM(qr.request_duration_ms) * COUNT(1)) * SUM(ra.thread_count) AS total_cost,
+ COUNT(1) AS num_runs
+ FROM v_monitor.query_requests qr
+ JOIN (SELECT transaction_id, statement_id, event_type
+ FROM v_internal.dc_execution_engine_events
+ WHERE node_name = (SELECT MIN(node_name)
+ FROM v_catalog.nodes)
+ ) eee USING (transaction_id, statement_id)
+ LEFT JOIN (SELECT transaction_id, statement_id, thread_count, memory_inuse_kb, duration_ms
+ FROM v_monitor.resource_acquisitions
+ WHERE node_name = (SELECT MIN(node_name)
+ FROM v_catalog.nodes)
+ ) ra USING (transaction_id, statement_id)
+ WHERE start_timestamp::date > CURRENT_DATE() -1
+ AND NOT qr.is_executing
+ AND eee.event_type IN ('GROUP_BY_SPILLED', 'JOIN_SPILLED')
+ GROUP BY 1
+HAVING COUNT(*) > 3
+ ORDER BY total_cost DESC
+ LIMIT 40;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: query-requests-overview
+# key: qro_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# expand-env: ((yas/indent-line 'auto) (yas/wrap-around-region 't))
+# --
+SELECT user_name,
+ start_timestamp,
+ request_duration_ms,
+ transaction_id,
+ STATEMENT_ID,
+ substr(request, 0, 1000) AS request
+ FROM v_monitor.query_requests
+WHERE transaction_id > 0
+ORDER BY request_duration_ms DESC
+LIMIT 10;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: query-times
+# key: qt_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT DISTINCT theday,
+ user_name,
+ (min_dat / 1000) AS min_sec,
+ (max_dat / 1000) AS max_sec,
+ (avg_dat / 1000) AS avg_sec,
+ (median_dat / 1000) AS median_sec,
+ query_cnt
+FROM
+ (SELECT date(end_timestamp::TIMESTAMP) AS theday,
+ user_name,
+ min(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) min_dat,
+ max(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) max_dat,
+ avg(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) avg_dat,
+ median(request_duration_ms) over(partition BY date(end_timestamp::TIMESTAMP), user_name) median_dat,
+ count(*) over(partition BY date(end_timestamp::TIMESTAMP), user_name) AS query_cnt
+ FROM query_requests
+ WHERE is_executing IS FALSE
+ AND request ILIKE '%table%'
+ AND NOT (request LIKE 'SELECT * FROM columns%'
+ OR request LIKE '%query_requests%') ) my_alias
+ORDER BY 1 DESC, 2;
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: rebalance_projection_status
+# key: rps_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT projection_name, rebalance_method, separated_percent, transferred_percent
+ FROM v_monitor.rebalance_projection_status
+ WHERE rebalance_method = 'ELASTIC_CLUSTER'
+ AND (
+ separated_percent <> 0
+ AND separated_percent <> 100
+ )
+ OR (
+ transferred_percent <> 0
+ AND transferred_percent <> 100
+ )
+ AND is_latest
+ ORDER BY 1;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: rebalance_status
+# key: rs_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT rebalance_method rebalance_method,
+ status,
+ count(*) AS COUNT
+FROM
+ (SELECT rebalance_method,
+ CASE
+ WHEN (separated_percent = 100
+ AND transferred_percent = 100) THEN 'Completed'
+ WHEN (separated_percent <> 0
+ AND separated_percent <> 100)
+ OR (transferred_percent <> 0
+ AND transferred_percent <> 100) THEN 'In Progress'
+ ELSE 'Queued'
+ END AS status
+ FROM v_monitor.rebalance_projection_status
+ WHERE is_latest) AS tab
+GROUP BY 1,
+ 2
+ORDER BY 1,
+ 2;$0
--- /dev/null
+# -*- mode: snippet -*-
+# name: rebalance_times
+# key: rt_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT dc_rebalanced_projections.node_name,
+ projection_schema,
+ projection_name,
+ start_time,
+ time -start_time duration
+ FROM v_internal.dc_rebalanced_projections
+ ORDER BY 5 DESC
+ LIMIT 100;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: resource-pool-move
+# key: rpmv
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM resource_pool_move ORDER BY move_timestamp DESC LIMIT 40;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: resource_pool_status
+# key: rps_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT node_name,
+ pool_name,
+ TO_CHAR( memory_size_kb / 1024, '999g999g999g999') AS memory_size_mb,
+ TO_CHAR( max_memory_size_kb / 1024, '999g999g999g999') AS max_memory_size_mb,
+ TO_CHAR( memory_size_actual_kb / 1024, '999g999g999g999') AS memory_size_actual_mb,
+ planned_concurrency,
+ TO_CHAR( query_budget_kb / 1024 , '999g999g999g999') AS query_budget_mb
+ FROM resource_pool_status
+ WHERE pool_name = '$1'
+ ORDER BY 1,2;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: resource_pool_status2
+# key: rps2_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT sysdate AS CURRENT_TIME,
+ node_name,
+ pool_name,
+ TO_CHAR( memory_inuse_kb / 1024 / 1024, '999g999g999g990d99') AS memory_inuse_gb,
+ TO_CHAR( general_memory_borrowed_kb / 1024 / 1024, '999g999g999g990d99') AS general_memory_borrowed_gb,
+ running_query_count,
+ max_concurrency
+ FROM resource_pool_status
+WHERE running_query_count > 0;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: resource_pools
+# key: pools_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM resource_pools;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: resources
+# key: res_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM ${1:$$(yas-choose-value '("resource_pool_status" "resource_pool_move" "resource_rejections" "resource_rejection_details ORDER BY 1"))};$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: ros_count
+# key: ro_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT node_name,
+ projection_schema,
+ projection_name,
+ SUM(ros_count) AS ros_count
+ FROM v_monitor.projection_storage
+ GROUP BY node_name,
+ projection_schema,
+ projection_name
+ HAVING SUM(ros_count) > 100
+ ORDER BY ros_count DESC;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: segmentation-islands1
+# key: si1_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+#
+# https://www.vertica.com/blog/beware-segmentation-islands/
+#
+# --
+SELECT REGEXP_REPLACE(SUBSTR(segment_expression, 1, 500), '\w+\.'),
+ COUNT(*)
+ FROM projections
+ WHERE projection_name NOT ILIKE '%b1'
+ GROUP BY 1
+ ORDER BY 2 DESC;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: segmentation-islands2
+# key: si2_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+#
+# https://www.vertica.com/blog/beware-segmentation-islands/
+#
+# --
+SELECT projection_schema || '.' || p.projection_name, REGEXP_REPLACE(SUBSTR(p.segment_expression, 1, 500), '\w+\.'),
+ pc.projection_column_name
+ FROM projections p
+ JOIN projection_columns pc USING (projection_id)
+ WHERE REGEXP_REPLACE(SUBSTR(p.segment_expression, 1, 500), '\w+\.')
+ IN (SELECT REGEXP_REPLACE(SUBSTR (p.segment_expression, 1, 500), '\w+\.')
+ FROM projections p
+ WHERE p.projection_name NOT ILIKE '%b1'
+ AND is_segmented
+ GROUP BY 1
+ HAVING COUNT(*) = 1 )
+ AND p.projection_name NOT ILIKE '%b1'
+ AND pc.projection_column_name IN (
+ SELECT hash_expr FROM (SELECT replace(substr(regexp_replace(substr(p.segment_expression, 1, 500), '\w+\.'), 6), ')', '') AS hash_expr, COUNT(*)
+ FROM projections p
+ WHERE p.projection_name NOT ILIKE '%b1'
+ AND is_segmented
+ GROUP BY 1
+ ORDER BY 2 DESC
+ LIMIT 20 ) AS foo )
+ ORDER BY 1, 2, 3;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: sessions
+# key: sess_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM sessions;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: storage-containers
+# key: storage-containers
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT s.node_name,
+ p.table_schema,
+ s.projection_name,
+ count(DISTINCT s.storage_oid) storage_container_count,
+ count(DISTINCT partition_key) partition_count,
+ count(r.rosid) ros_file_count
+FROM storage_containers s
+LEFT OUTER JOIN partitions p ON s.storage_oid = p.ros_id
+JOIN vs_ros r ON r.delid = s.storage_oid
+GROUP BY 1,
+ 2,
+ 3
+ORDER BY 4 DESC LIMIT 50;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: storage-locations
+# key: storage-locations
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT * FROM v_catalog.grants gra, storage_locations loc WHERE gra.object_id = loc.location_id;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: table_locks
+# key: tl_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT locks.lock_mode,
+ locks.lock_scope,
+ substr(locks.transaction_description, 1, 100) AS "left",
+ locks.request_timestamp,
+ locks.grant_timestamp
+ FROM v_monitor.locks;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: user_sessions
+# key: ussess_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT session_id, transaction_start FROM sessions WHERE user_name = '$1' ORDER BY 2 desc;$0
\ No newline at end of file
--- /dev/null
+# -*- mode: snippet -*-
+# name: vertica_users
+# key: vertu_
+# group: vertica
+# condition: (if (string-equal sql-product 'vertica)t)
+# --
+SELECT user_name,resource_pool,default_roles FROM v_catalog.users ORDER BY 1;
\ No newline at end of file
--- /dev/null
+sql-interactive-mode
--- /dev/null
+;;; vertica-snippets-autoloads.el --- automatically extracted autoloads
+;;
+;;; Code:
+
+(add-to-list 'load-path (directory-file-name
+ (or (file-name-directory #$) (car load-path))))
+
+\f
+;;;### (autoloads nil "vertica-snippets" "vertica-snippets.el" (0
+;;;;;; 0 0 0))
+;;; Generated autoloads from vertica-snippets.el
+
+(autoload 'vertica-snippets-initialize "vertica-snippets" "\
+Add snippet dir to yas-snippet-dirs and load it." nil nil)
+
+(eval-after-load 'yasnippet '(vertica-snippets-initialize))
+
+(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "vertica-snippets" '("vertica-snippets-dir")))
+
+;;;***
+\f
+;;;### (autoloads nil nil ("vertica-snippets-pkg.el") (0 0 0 0))
+
+;;;***
+\f
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; coding: utf-8
+;; End:
+;;; vertica-snippets-autoloads.el ends here
--- /dev/null
+(define-package "vertica-snippets" "20200423.1200" "Yasnippets for Vertica"
+ '((yasnippet "0.6.1"))
+ :commit "6ced718d9120878878700592fab430a8542b748f" :authors
+ '(("Andreas Gerler" . "baronNOSPAMbundesbrandschatzamt.de"))
+ :maintainer
+ '("Andreas Gerler" . "baronNOSPAMbundesbrandschatzamt.de")
+ :keywords
+ '("convenience" "snippets")
+ :url "https://github.com/baron42bba/vertica-snippets")
+;; Local Variables:
+;; no-byte-compile: t
+;; End:
--- /dev/null
+;;; vertica-snippets.el --- Yasnippets for Vertica
+
+;; Copyright (C) 2018 Andreas Gerler
+;; keywords: convenience,snippets
+;; Version: 0.1.0
+;; Package-Requires: ((yasnippet "0.6.1"))
+
+;; Author: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
+;; Maintainer: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
+
+;; URL: https://github.com/baron42bba/vertica-snippets
+
+;; Permission is hereby granted, free of charge, to any person obtaining
+;; a copy of this software and associated documentation files (the
+;; "Software"), to deal in the Software without restriction, including
+;; without limitation the rights to use, copy, modify, merge, publish,
+;; distribute, sublicense, and/or sell copies of the Software, and to
+;; permit persons to whom the Software is furnished to do so, subject to
+;; the following conditions:
+
+;; The above copyright notice and this permission notice shall be
+;; included in all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+;;; Commentary:
+
+;; A collection of yasnippet snippets to be used with the Vertica Analytics Platform
+
+;;; Code:
+
+(require 'yasnippet)
+
+(defvar vertica-snippets-dir (file-name-directory (or (buffer-file-name)
+ load-file-name)))
+
+;;;###autoload
+(defun vertica-snippets-initialize ()
+ "Add snippet dir to yas-snippet-dirs and load it."
+ (let ((snip-dir (expand-file-name "snippets" vertica-snippets-dir)))
+ (add-to-list 'yas-snippet-dirs snip-dir t)
+ (yas-load-directory snip-dir)))
+
+;;;###autoload
+(eval-after-load 'yasnippet
+ '(vertica-snippets-initialize))
+
+(provide 'vertica-snippets)
+;;; vertica-snippets.el ends here