1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-31 06:54:51 +09:00

Refactor undirected edge SQL to remove repeated filter

This commit is contained in:
fr33domlover 2016-08-02 09:29:56 +00:00
parent 9cfaabc035
commit 521871c476

View file

@ -169,6 +169,9 @@ infixr 5 ?++
uedge :: DBName uedge :: DBName
uedge = DBName "temp_undirected_edge_cte" uedge = DBName "temp_undirected_edge_cte"
ubase :: DBName
ubase = DBName "temp_undirected_base_cte"
temp :: DBName temp :: DBName
temp = DBName "temp_hierarchy_cte" temp = DBName "temp_hierarchy_cte"
@ -188,8 +191,8 @@ sqlUEdge
:: (DBName -> Text) -> Text -> EntityDef -> FieldDef -> FieldDef -> Text :: (DBName -> Text) -> Text -> EntityDef -> FieldDef -> FieldDef -> Text
sqlUEdge dbname filt tEdge bwd fwd = sqlUEdge dbname filt tEdge bwd fwd =
let t ^* f = dbname t <> "." <> dbname f let t ^* f = dbname t <> "." <> dbname f
in mconcat sqlBase = mconcat
[ dbname uedge [ dbname ubase
, " (" , " ("
, dbname $ fieldDB bwd, ", ", dbname $ fieldDB fwd , dbname $ fieldDB bwd, ", ", dbname $ fieldDB fwd
, ") AS (SELECT " , ") AS (SELECT "
@ -198,11 +201,20 @@ sqlUEdge dbname filt tEdge bwd fwd =
, entityDB tEdge ^* fieldDB fwd , entityDB tEdge ^* fieldDB fwd
, " FROM ", dbname $ entityDB tEdge , " FROM ", dbname $ entityDB tEdge
, filt , filt
, "), "
]
sqlEdge base = mconcat
[ dbname uedge
, " ("
, dbname $ fieldDB bwd, ", ", dbname $ fieldDB fwd
, ") AS (SELECT "
, base ^* fieldDB bwd, ", ", base ^* fieldDB fwd
, " FROM ", dbname base
, " UNION ALL SELECT " , " UNION ALL SELECT "
, entityDB tEdge ^* fieldDB fwd , base ^* fieldDB fwd, ", ", base ^* fieldDB bwd
, ", " , " FROM ", dbname base
, entityDB tEdge ^* fieldDB bwd
, " FROM ", dbname $ entityDB tEdge
, filt
, ")" , ")"
] ]
in if T.null filt
then sqlEdge $ entityDB tEdge
else sqlBase <> sqlEdge ubase