Skip to content

Instantly share code, notes, and snippets.

View xtender's full-sized avatar

Sayan Malakshinov xtender

View GitHub Profile
@xtender
xtender / connect_by.sql
Created July 6, 2015 22:47
connect by nocycle
with v as (select origin a ,destination b from network_table
union all
select destination,origin from network_table
)
,v1 as (
select distinct a,b
from v
start with a=11
connect by nocycle prior b = a
)
SQL> ;
1 with v as (select origin a, destination b, '->' direction from network_table
2 union all
3 select destination a, origin b, '<-' direction from network_table
4 )
5 ,v1 as (
6 select distinct a,direction, b
7 from v
8 start with a=24
9 connect by nocycle prior b = a
@xtender
xtender / gist:6f77aaa144c3aa3d985b
Created July 7, 2015 12:55
connect_by + hints
with v as (select/*+ inline */ *
from (
select origin a ,destination b from network_table
union all
select destination,origin from network_table
)
)
,v1 as (
select/*+ merge(v) inline */
distinct a,b
Plan hash value: 3545196243
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes|E-Temp | Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | | 1734 (100)| | 10 |00:00:00.01 | 36 | | | |
| 1 | HASH UNIQUE | | 1 | 6 | 78 | | 1734 (1)| 00:00:21 | 10 |00:00:00.01 | 36 | 2441K| 2441K| 1105K (0)|
|* 2 | VIEW
@xtender
xtender / gist:d4ae1e63364b91bf4c04
Created July 7, 2015 13:27
hinted plan 12.1.0.2
Plan hash value: 970741584
----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes|E-Temp | Cost (%CPU)| E-Time | OMem | 1Mem | Used-Mem |
----------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | | 1734 (100)| | | | |
| 1 | HASH UNIQUE | | 6 | 78 | | 1734 (1)| 00:00:01 | 2442K| 2442K| 1105K (0)|
|* 2 | VIEW | | 6 | 78 | | 1733 (1)| 00:00:01 | | | |
| 3 | UNPIVOT |
set echo on feed on timing on serverout off;
drop table network_table purge;
create table network_table (
origin number
, destination number
)
/
begin
insert into network_table values (11, 12);
@xtender
xtender / output.sql
Created July 7, 2015 14:10
typical +adaptive
SQL> select * from table(dbms_xplan.display('','','typical +adaptive'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 970741584
--------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 78 | | 1734 (1)| 00:00:01 |
with
function cx(x int) return float deterministic as
begin
return -2.2 + 0.031 * x;
end;
function cy(y int) return float deterministic as
begin
return -1.5 + 0.031 * y;
end;
@xtender
xtender / Votes.sql
Created September 17, 2015 15:00
Upvotes downvotes
with v(name,points,votes) as (
select 'Sean Stuber' , 230, 57 from dual union all
select 'Matthias Rogel' , 40, 22 from dual union all
select 'Erik Van Roon' , 0, 24 from dual union all
select 'Emrah Mete' , 920, 120 from dual union all
select 'Sayan Malakshinov',1090, 161 from dual union all
select 'Kim Berg Hansen' , 140, 48 from dual union all
select 'Justin Cave' , 110, 35 from dual union all
select 'Stew Ashton' , 80, 26 from dual
)
@xtender
xtender / sqlcl.bat
Created October 6, 2015 20:13
sqlcl.bat
@echo off
REM ########################################################################
REM # (@)sql.bat
REM #
REM # Copyright 2014 by Oracle Corporation,
REM # 500 Oracle Parkway, Redwood Shores, California, 94065, U.S.A.
REM # All rights reserved.
REM #
REM # This software is the confidential and proprietary information
REM # of Oracle Corporation.