nosql la nuova frontiera dei database [db05-s]
TRANSCRIPT
![Page 1: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/1.jpg)
Ordine degli Ingegneri della Provincia di SiracusaSabato 5 Marzo 2016 [Sala Convegni – Siracusa]
noSQL La nuova frontiera dei
DatabaseRelatore: Ing. Andrea Maddalena
![Page 2: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/2.jpg)
Ing. Andrea Maddalena DBA e Software Developer (dal 2000)
Database:mySQL, MS SQL Server (2000-2014), Oracle db, postreSQL, SQLite, dBase, MongoDB, Redis, Azure blob …
Linguaggi:C, C++, Java, C#, VB, VBA, Javascript, Node.js, Python …
Laurea Ingegneria ElettronicaOrdine Ingegneri Siracusa – 1602/A
M101JS: MongoDB for Node.js DeveloperM101N: MongoDB for .NET DeveloperM102: MongoDB for DBAs
![Page 3: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/3.jpg)
Agenda Introduzione RDBMS Evoluzione Infrastruttura noSQL Document DB Key Value Storage
![Page 4: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/4.jpg)
4
Introduzione
Banca dati (database)
Introduzione
« Insieme organizzato di dati gestito da un DBMS. Sue
caratteristiche sono la grandezza, la condivisibilità e la
persistenza: una banca dati è grande perché in generale ha una
dimensione tale da richiedere l’utilizzo della memoria secondaria
per la sua gestione, condivisa, perché accessibile da più
applicazioni e utenti, e persistente, perché ha un ciclo di vita
indipendente da quello dei programmi che la utilizzano. »Fonte: Treccani [http://www.treccani.it/enciclopedia/banca-dati/]
![Page 5: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/5.jpg)
5
Database
Un database deve soddisfare i seguenti requisiti: i dati devono essere organizzati con ridondanza
minima; i dati devono essere utilizzabili
contemporaneamente da più utenti.
Introduzione
![Page 6: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/6.jpg)
6
Database Management System
I DBMS sono strumenti software che hanno il compito di gestire le informazioni contenute in un database in maniera efficiente ed efficace.
Introduzione
App 1
App 2
App 3
Dati
Dati
Dati
App 1
App 1
App 1
DBMS
![Page 7: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/7.jpg)
7
DBMS Caratteristiche
Le capacità fondamentali di un DBMS sono: gestire dati non volatili accedere in modo efficiente a grandi quantità di dati
Introduzione
Modello dati Linguaggio di alto livello Transazioni
Accesso controllato Recupero dati
Ulteriori caratteristiche
![Page 8: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/8.jpg)
8
Progettazione database
schema concettuale
Progetto concettuale schema logicoProgetto
logico schema fisicoProgetto fisico
Introduzione
Le fasi fondamentali nella progettazione di un database sono:
![Page 9: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/9.jpg)
RDBMSRelational Database Management System
![Page 10: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/10.jpg)
10
Database Relazionale - RDBMS«Il termine Relational database management system (RDBMS) indica un database management system basato sul modello relazionale»
RDBMSFonte: Wikipedia [https://it.wikipedia.org/wiki/Modello_relazionale]
La struttura base del modello relazionale è composta da: uno o più attributi (denominati campi); un tipo di dato o dominio per ciascuno degli attributi; un valore per ciascun attributo all'interno del dominio o tipo di dato consentito; una tupla cioè l'insieme non ordinato di valori assunti dagli attributi.
![Page 11: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/11.jpg)
11
RDBMS - Elementi
• Tabelle Chiavi primarie Chiavi esterne Tipo di dati Valori
RDBMS
• Viste (Query)• Procedure• …
![Page 12: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/12.jpg)
12
Normalizzazione
« La normalizzazione è un procedimento volto all'eliminazione della ridondanza informativa e del rischio di incoerenza dal database »
RDBMSFonte: Wikipedia [https://it.wikipedia.org/wiki/Normalizzazione_(informatica)]
Prima Forma Normale Seconda Forma
Normale Terza Forma Normale
Elimina gruppi ripetitiviElimina dati ridondantiElimina campi non dipendenti dalla chiave
![Page 13: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/13.jpg)
13
Prima Forma Normale
Si dice che una base dati è in 1NF (prima forma normale) se ogni relazione contenuta nella base dati è in 1NF, ovvero se e solo se:
1. tutte le righe della relazione hanno lo stesso numero di attributi
2. non presenta gruppi di attributi che si ripetono (ossia ciascun attributo è definito su un dominio con valori atomici)
3. tutti i valori di un attributo sono dello stesso tipo (appartengono allo stesso dominio)
4. esiste una chiave primaria (ossia esiste un insieme di attributi, che identifica in modo univoco ogni tupla della relazione)
5. l'ordine delle righe è irrilevante (non è portatore di informazioni)
RDBMSFonte: Wikipedia [https://it.wikipedia.org/wiki/Normalizzazione_(informatica)]
![Page 14: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/14.jpg)
14
Prima Forma Normale
RDBMS
prot# Impresa Impr_comune Collaudatore1 Collaudatore2 Collaudatore3
1022 Edil Srl Siracusa 908A 486A 695A
4123 Costruz. Srl Catania 862A 1602A 1929A
prot# Impresa Impr_comune Collaudatore
1022 Edil Srl Siracusa 908A
1022 Edil Srl Siracusa 486A
1022 Edil Srl Siracusa 695A
4123 Costruz. Srl Catania 862A
4123 Costruz. Srl Catania 1602A
4123 Costruz. Srl Catania 1929A
Tabella NON Normalizzata
Tabella 1NF: elimina gruppi ripetitivi
![Page 15: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/15.jpg)
15
Seconda Forma Normale
Si dice che una base dati è in 2NF (seconda forma
normale), quando è in 1NF e per ogni relazione tutti gli attributi non chiave dipendono funzionalmente dall'intera chiave composta (ovvero la relazione non ha attributi che dipendono funzionalmente da una parte della chiave).
RDBMSFonte: Wikipedia [https://it.wikipedia.org/wiki/Normalizzazione_(informatica)]
![Page 16: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/16.jpg)
16
Seconda Forma Normale
RDBMS
prot# Impresa Impr_Comune1022 Edil Srl Siracusa
4123 Costruz. Srl Catania
prot# Collaudatore#
1022 908A
1022 486A
1022 695A
4123 862A
4123 1602A
4123 1929A
Tabelle 2NF: elimina dati ridondanti
Richieste
Segnalazioni
prot# Impresa Impr_com Collaud
1022 Edil Srl Siracusa 908A
1022 Edil Srl Siracusa 486A
1022 Edil Srl Siracusa 695A
4123 Costruz. Srl Catania 862A
4123 Costruz. Srl Catania 1602A
4123 Costruz. Srl Catania 1929A
Tabelle 1NF
![Page 17: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/17.jpg)
17
Terza Forma Normale
Si dice che una base dati è in 3NF (terza forma
normale) se è in 2NF e tutti gli attributi non-chiave dipendono dalla chiave soltanto, ossia non esistono attributi che dipendono da altri attributi non-chiave.
RDBMSFonte: Wikipedia [https://it.wikipedia.org/wiki/Normalizzazione_(informatica)]
![Page 18: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/18.jpg)
18
Terza Forma Normale
RDBMS
Tabelle 3NF: elimina dati non dipendentidalla chiave
Richieste
Segnalazioni
prot# ID_Imp
1022 1
4123 2
ID_Imp Rag_Soc Comune
1 Edil Srl Siracusa
2 Costruz. Srl Catania
prot# Collaudatore#
1022 908A
1022 486A
1022 695A
4123 862A
4123 1602A
4123 1929A
Imprese
![Page 19: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/19.jpg)
19
Schema - Relazioni
RDBMS
![Page 20: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/20.jpg)
20
Tipo di dati
RDBMS
TipoDati Utilizzo / Descrizione Dimensione
Money Valuta o Contabilità [da -922.337.203.685.477,5808 a 922.337.203.685.477,5807] 8 bytes
Int Intero [da -2^31 (-2,147,483,648) a 2^31-1 (2,147,483,647)] 4 bytes
Float Numero con virgola mobile [da - 1.79E+308 a -2.23E-308, 0 e da 2.23E-308 a 1.79E+308]
Depends on the value of n
Datetime Data [da Gennaio 1, 1753, a Dicembre 31, 9999] Tempo [da 00:00:00 a 23:59:59.997]
8 bytes
Char Stringa a lunghezza fissa (non-Unicode) [da 1 a 8.000 caratteri] n bytes
Varchar Stringa a lunghezza variabile (non-Unicode) [da 1 a 8.000 caratteri] Actual length + 2 bytesBit Intero [valore 0 o 1] 1 byte for every 8 bit
columnsDatetimeoffset Data [da Gennaio 1, 1 A.D., a Dicembre 31, 9999 A.D.]
Tempo [da 00:00:00 a 23:59:59.997]Time zone [da -14:00 a +14:00]
10 Bytes
![Page 21: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/21.jpg)
RDBMSDEMO
DB Access(Struttura dati su file)
MS SQL Server 2012(Gestione RDBMS con Management Studio)
Software TCA (Segnalazione Terne di Collaudo)
![Page 22: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/22.jpg)
22
Database Relazionale - Vantaggi
• Maturità della soluzione• Consistenza dei dati• Integrità dei dati• Uso efficiente dello spazio (se normalizzato)• Linguaggio di interrogazione (query)• Diffusione e facilità nel trovare supporto tecnico
RDBMS
![Page 23: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/23.jpg)
23
Database Relazionale - Criticità
• Scalabilità verticale (scaling up)• Soluzione centralizzata
• Singolo punto di failure• Replica con elevata consistenza dei dati
• Soluzione rigida (non flessibile)• Difficoltà di gestione dati semi-strutturati e non-strutturati• Consumo risorse per operazioni di join (causa normalizzazione)
RDBMS
![Page 24: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/24.jpg)
24
RDBMS in Commercio
• Access• Microsoft SQL Server• Oracle mySQL• Oracle Database 12c• postgreSQL
RDBMS
![Page 25: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/25.jpg)
25
Operational Database Management System
RDBMSFonte: https://info.microsoft.com/CO-SQL-CNTNT-FY16-09Sep-14-MQOperational-Register.html
Gartner recognized Microsoft as a Leader once again in the 2015 Magic Quadrant for Operational Database Management Systems, positioning it furthest to the right on the axis for completeness of vision, and closest to the top on the axis for ability to execute.
![Page 26: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/26.jpg)
Evoluzione InfrastrutturaCome l'infrastruttura hardware incide sullo sviluppo software
![Page 27: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/27.jpg)
27
Two TiersLe soluzioni Two-Tiers sono basate su una infrastruttura Client / Server
Evoluzione Infrastruttura
Data Server
Client
Client
Tasks/Services Application Services Business Services Data Services
Tasks/Services User Interface Presentation Services Application Services
![Page 28: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/28.jpg)
28
Three TiersLe soluzioni Three-Tiers mantengono l'architettura Client / Server con l'aggiunta di uno specifico
livello dedicato alla parte applicativa
Evoluzione Infrastruttura
Client
Livello DatiLe informazioni sono archiviate e recuperate su Database e/o File System,
Application Layer/Server
Data Layer/Server
Client
Livello Applicazione (Business Logic)Esegue le operazioni di elaborazione e controllo effettuando accesso ai dati.
Livello PresentazioneMostra le informazioni all'utente e dispone dei comandi per esecuzione della logica applicativa
![Page 29: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/29.jpg)
29
MultiTiersLe soluzioni Multi-Tiers possono essere implementate sia a livello di infrastruttura hardware che come
metodologia di sviluppo software
Evoluzione Infrastruttura
Client
Client
Domain Controller
App. Server
Web Server
Data Server
File ServerMobile
![Page 30: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/30.jpg)
30
Services
Evoluzione InfrastrutturaFonte: Building Microservices [O'Reilly Media - ISBN: 9781491950357]
![Page 31: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/31.jpg)
31
Services
Evoluzione InfrastrutturaFonte: Building Microservices [O'Reilly Media - ISBN: 9781491950357]
![Page 32: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/32.jpg)
32
Virtualizzazione
Evoluzione InfrastrutturaFonte: Building Microservices [O'Reilly Media - ISBN: 9781491950357]
![Page 33: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/33.jpg)
noSQL
![Page 34: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/34.jpg)
34
noSQL Evoluzione
noSQLFonte: [http://www.slideshare.net/KaramjitCheema/no-sql-20259146?related=1 ]
NoSQL è un movimento che promuove sistemi software dove la persistenza dei dati è caratterizzata dal fatto di non utilizzare il modello relazionale.
http://nosql-database.org/
![Page 35: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/35.jpg)
35
noSQL - Vantaggi
• Soluzione semplice (riduzione della complessità)• Elevato capacità di comunicazione dati (throughtput)• Scalabilità Orizzontale (scale out)• Riduzione costi• Elimina ORM• Flessibilità modello dati (schema-less)• Riduzione carico di lavoro DBA
noSQL
![Page 36: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/36.jpg)
36
noSQL DatabaseTipologia database noSQL
noSQL
Key / Value Column Graph Document DB
![Page 37: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/37.jpg)
Document DBmongoDB
![Page 38: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/38.jpg)
38
MongoDB Caratteristiche
MongoDB è un database noSQL open-source di uso generale, con le seguenti caratteristiche:• Modello di documento dati con schemi dinamici• Supporto di indicizzazione pieno e flessibile e ricche query• Modulo auto-sharding per la scalabilità orizzontale• Replicazione integrata per un’elevata disponibilità• Ricerca testuale• Sicurezza avanzata• Framework per aggregazioni e MapReduce• Ampio storage di memorizzazione con GridFS
Document DB
![Page 39: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/39.jpg)
39
Google Trends
Document DB
![Page 40: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/40.jpg)
40
MongoDB
Document DB
![Page 41: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/41.jpg)
41
Formato Documenti
MongoDB archivia i dati sotto forma di documenti in formato JSON-like
nome : valore
Document DB
![Page 42: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/42.jpg)
42
JSONJSON (JavaScript Object Notation) è un semplice formato per lo scambio di dati.
Document DBFonte: http://www.json.org/json-it.html
JSON è basato su due strutture:• Un insieme di coppie nome/valore. In diversi linguaggi, questo è realizzato come un
oggetto, un record, uno struct, un dizionario, una tabella hash, un elenco di chiavi o un array associativo.
• Un elenco ordinato di valori. Nella maggior parte dei linguaggi questo si realizza con un array, un vettore, un elenco o una sequenza.
![Page 43: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/43.jpg)
43
JSONJSON (JavaScript Object Notation) è un semplice formato per lo scambio di dati.
Document DBFonte: http://www.json.org/json-it.html
![Page 44: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/44.jpg)
44
CRUD
Document DB
![Page 45: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/45.jpg)
45
CRUD
Document DB
![Page 46: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/46.jpg)
46
CRUDdb.inventory.update( { item: "MNO2" }, { $set: { category: "apparel", details: { model: "14Q3", manufacturer: "XYZ Company" } }, $currentDate: { lastModified: true } })
Document DB
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1
})
![Page 47: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/47.jpg)
47
CRUD
db.inventory.remove( { } )
Document DB
db.inventory.remove( { type : "food" } )
A differenza del comando Update, nel caso di Remove non è prevista l’opzione upsert in quanto il remove è eseguito per tutti i documenti per i quali il filtro è verificato
![Page 48: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/48.jpg)
48
CURSORIvar myCursor = db.inventory.find( { type: 'food' } );
myCursor
Document DB
while (myCursor.hasNext()) { print(tojson(myCursor.next()));}
![Page 49: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/49.jpg)
MongoDB
DEMOMongoDB
(Installazione e Servizi)
MongoShell(Console di Gestione)
![Page 50: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/50.jpg)
50
Aggregazione dati
Document DB
I comandi di Aggregazione utilizzano la pipeline di esecuzione che permette delle elaborazioni consecutive con diversi operatori di aggregazione
![Page 51: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/51.jpg)
51
Aggregazione datiSQL Terms, Functions, and Concepts MongoDB Aggregation Operators
WHERE $matchGROUP BY $groupHAVING $matchSELECT $projectORDER BY $sortLIMIT $limitSUM() $sumCOUNT() $sum
joinNo direct corresponding operator; however, the $unwind operator allows for somewhat similar functionality, but with fields embedded within the document.
Document DB
![Page 52: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/52.jpg)
52
Struttura RDBMS / MongoDB
Struttura RDBMS
![Page 53: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/53.jpg)
53
Blog –RDBMS vs MongoDB
Document DB
![Page 54: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/54.jpg)
54
Architettura
Document DB
![Page 55: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/55.jpg)
55
Storage Engine
Document DB
![Page 56: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/56.jpg)
56
Replica
Document DB
{"_id" : 0,"host" : "localhost:27017","arbiterOnly" : false,"buildIndexes" : true,"hidden" : false,"priority" : 1,"tags" : { },"slaveDelay" : 0,"votes" : 1
},
Rs.config() - nodo
![Page 57: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/57.jpg)
57
Sharding
Document DB
![Page 58: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/58.jpg)
58
Scale out
Document DB
![Page 59: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/59.jpg)
Key Value Storage
![Page 60: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/60.jpg)
60
Redis• Redis è un open source, advanced key-value data store
• Considerato come un data structure server per il fatto che le chiavi (keys) possono contenere strings, hashes, lists, sets and sorted sets
• Redis lavora con dataset in-memory
• È possibile archiviare I dati in modo persistente• dumping the dataset to disk every once in a while• or by appending each command to a log
Key Value Storage
![Page 61: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/61.jpg)
61
Redis Server
Key Value Storage
• Run /redis/bin/redis-server.exe and specify configuration file to useredis>redis-server redis.conf
![Page 62: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/62.jpg)
Running Redis Client
• Run /redis/bin/redis-cli.exe
![Page 63: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/63.jpg)
Useful Commands
• Print all keys:
• Remove all keys from all databases
• Synchronously save the dataset to disk
KEYS *
FLUSHALL
SAVE
![Page 64: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/64.jpg)
Redis keys
• Keys are binary safe - it is possible to use any binary sequence as a key• The empty string is also a valid key• Too long keys are not a good idea• Too short keys are often also not a good
idea ("u:1000:pwd" versus "user:1000:password")• Nice idea is to use some kind of schema,
like: "object-type:id:field"
![Page 65: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/65.jpg)
Redis data types
Redis is often referred to as a data structure server since keys can contain:• Strings• Lists• Sets• Hashes• Sorted Sets
![Page 66: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/66.jpg)
Redis Strings
• Most basic kind of Redis value
• Binary safe - can contain any kind of data, for instance a JPEG image or a serialized Ruby object
• Max 512 Megabytes in length
• Can be used as atomic counters using commands in the INCR family
• Can be appended with the APPEND command
![Page 67: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/67.jpg)
Redis Strings: Example
![Page 68: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/68.jpg)
Redis Lists
• Lists of strings, sorted by insertion order• Add elements to a Redis List pushing new
elements on the head (on the left) or on the tail (on the right) of the list• Max length: (2^32 - 1) elements• Model a timeline in a social network, using
LPUSH to add new elements, and using LRANGE in order to retrieve recent items• Use LPUSH together with LTRIM to create a list
that never exceeds a given number of elements
![Page 69: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/69.jpg)
Redis Lists: Example
![Page 70: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/70.jpg)
Redis Sorted Sets
• Every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score
• You can do a lot of tasks with great performance that are really hard to model in other kind of databases
• Probably the most advanced Redis data type
![Page 71: noSQL La nuova frontiera dei Database [DB05-S]](https://reader036.vdocumenti.com/reader036/viewer/2022062503/5883f85b1a28ab34428b7a61/html5/thumbnails/71.jpg)
Conclusione Grazie per la partecipazione
Ing. Andrea [email protected]
http://www.aeisolution.ithttps://it.linkedin.com/in/ingmaddalena
Ordine degli Ingegneri della Provincia di Siracusa
Siracusa, lì 05/03/2016